ldap_server: chunk the writev() calls at 25MB
authorAndrew Bartlett <abartlet@samba.org>
Tue, 14 May 2019 00:08:03 +0000 (12:08 +1200)
committerAndrew Bartlett <abartlet@samba.org>
Mon, 20 May 2019 04:01:11 +0000 (04:01 +0000)
This should limit the amount we send to GENSEC at a
time where it may help avoid large realloc or memcpy calls.

Signed-off-by: Andrew Bartlett <abartlet@samba.org>
Reviewed-by: Gary Lockyer <gary@catalyst.net.nz>
source4/ldap_server/ldap_server.c
source4/ldap_server/ldap_server.h

index 53e9af94888fa92ee423506a58f6a0225051c3d7..4d3d8cd1188ec7c6a1409058e3c4ee29972f939f 100644 (file)
@@ -683,9 +683,16 @@ static void ldapsrv_call_writev_start(struct ldapsrv_call *call)
        for (reply = call->replies;
             reply != NULL;
             reply = reply->next) {
+
+               /* Cap output at 25MB per writev() */
+               if (length > length + reply->blob.length
+                   || length + reply->blob.length > LDAP_SERVER_MAX_CHUNK_SIZE) {
+                       break;
+               }
+
                /*
                 * Overflow is harmless here, just used below to
-                * decide if to read or write
+                * decide if to read or write, but checkd above anyway
                 */
                length += reply->blob.length;
 
index 48634e7610c2a791032c6b47bdc15934b9a9a9c2..bee6ce7d5be89a0ded2953a8cc525ed2914e2a2e 100644 (file)
@@ -100,6 +100,11 @@ struct ldapsrv_call {
  */
 #define LDAP_SERVER_MAX_REPLY_SIZE ((size_t)(256 * 1024 * 1024))
 
+/*
+ * Start writing to the network before we hit this size
+ */
+#define LDAP_SERVER_MAX_CHUNK_SIZE ((size_t)(25 * 1024 * 1024))
+
 struct ldapsrv_service {
        struct tstream_tls_params *tls_params;
        struct task_server *task;