Only send the used portion of struct idm_req in imsgs from the ldapclient
authorjmatthew <jmatthew@openbsd.org>
Fri, 31 Mar 2023 03:38:26 +0000 (03:38 +0000)
committerjmatthew <jmatthew@openbsd.org>
Fri, 31 Mar 2023 03:38:26 +0000 (03:38 +0000)
process to the main process. This significantly reduces memory usage when
updating larger directories.

ok aisha@

usr.sbin/ypldap/ldapclient.c
usr.sbin/ypldap/ypldap.c

index f9e089a..c47fb23 100644 (file)
@@ -1,4 +1,4 @@
-/* $OpenBSD: ldapclient.c,v 1.46 2022/10/13 04:55:33 jmatthew Exp $ */
+/* $OpenBSD: ldapclient.c,v 1.47 2023/03/31 03:38:26 jmatthew Exp $ */
 
 /*
  * Copyright (c) 2008 Alexander Schrijver <aschrijver@openbsd.org>
@@ -567,7 +567,8 @@ client_search_idm(struct env *env, struct idm *idm, struct aldap *al,
 
                        if (client_build_req(idm, &ir, m, min_attr, max_attr) == 0)
                                imsg_compose_event(env->sc_iev, type, 0, 0, -1,
-                                   &ir, sizeof(ir));
+                                   &ir, sizeof(ir.ir_key) +
+                                   strlen(ir.ir_line) + 1);
 
                        aldap_freemsg(m);       
                }
index 0d3d117..8aa2c2b 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: ypldap.c,v 1.23 2022/08/22 08:02:02 jmatthew Exp $ */
+/*     $OpenBSD: ypldap.c,v 1.24 2023/03/31 03:38:26 jmatthew Exp $ */
 
 /*
  * Copyright (c) 2008 Pierre-Yves Ritschard <pyr@openbsd.org>
@@ -392,7 +392,7 @@ main_dispatch_client(int fd, short events, void *p)
                        if (env->update_trashed)
                                break;
 
-                       (void)memcpy(&ir, imsg.data, sizeof(ir));
+                       (void)memcpy(&ir, imsg.data, n - IMSG_HEADER_SIZE);
                        if ((ue = calloc(1, sizeof(*ue))) == NULL ||
                            (ue->ue_line = strdup(ir.ir_line)) == NULL) {
                                /*
@@ -418,7 +418,7 @@ main_dispatch_client(int fd, short events, void *p)
                        if (env->update_trashed)
                                break;
 
-                       (void)memcpy(&ir, imsg.data, sizeof(ir));
+                       (void)memcpy(&ir, imsg.data, n - IMSG_HEADER_SIZE);
                        if ((ge = calloc(1, sizeof(*ge))) == NULL ||
                            (ge->ge_line = strdup(ir.ir_line)) == NULL) {
                                /*