From: Andreas Schneider Date: Wed, 22 Oct 2025 07:33:56 +0000 (+0200) Subject: lib:ldb:tools: Do not leak memory in ldb_cmdline_process_internal() X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=31158d62e55badd9e26291842dace1ffe70157c8;p=thirdparty%2Fsamba.git lib:ldb:tools: Do not leak memory in ldb_cmdline_process_internal() If add_control() hasn't been called before, it will be NULL. Use ret as the context to allocate memory on. Direct leak of 110 byte(s) in 1 object(s) allocated from: #0 0x7fc1b5921c2b in malloc (/lib64/libasan.so.8+0x121c2b) (BuildId: 388ee9ac193f74c177c6f52988d2d0dab110de41) #1 0x7fc1b56ed6a0 in __talloc_with_prefix ../../lib/talloc/talloc.c:783 #2 0x7fc1b56ee9e8 in __talloc ../../lib/talloc/talloc.c:825 #3 0x7fc1b56ee9e8 in __talloc_strlendup ../../lib/talloc/talloc.c:2454 #4 0x7fc1b56ee9e8 in talloc_strdup ../../lib/talloc/talloc.c:2470 #5 0x7fc1b5f1ad18 in ldb_cmdline_process_internal ../../lib/ldb/tools/cmdline.c:389 #6 0x7fc1b5f1b53c in ldb_cmdline_process ../../lib/ldb/tools/cmdline.c:544 #7 0x000000202a19 in main ../../lib/ldb/tools/ldbdel.c:97 #8 0x7fc1b542b2fa in __libc_start_call_main (/lib64/libc.so.6+0x2b2fa) (BuildId: 8523b213e7586a93ab00f6dd476418b1e521e62c) #9 0x7ffdced96847 ([stack]+0x38847) Signed-off-by: Andreas Schneider Reviewed-by: Noel Power Autobuild-User(master): Andreas Schneider Autobuild-Date(master): Wed Oct 22 09:25:35 UTC 2025 on atb-devel-224 --- diff --git a/lib/ldb/tools/cmdline.c b/lib/ldb/tools/cmdline.c index a6d51dffc92..4f6068b985f 100644 --- a/lib/ldb/tools/cmdline.c +++ b/lib/ldb/tools/cmdline.c @@ -386,10 +386,10 @@ static struct ldb_cmdline *ldb_cmdline_process_internal(struct ldb_context *ldb, t = strchr(p, ','); if (t == NULL) { - c = talloc_strdup(options.controls, p); + c = talloc_strdup(ret, p); p = NULL; } else { - c = talloc_strndup(options.controls, p, t-p); + c = talloc_strndup(ret, p, t-p); p = t + 1; } if (c == NULL || !add_control(ret, c)) {