[PATCH] avoid double-strlen in ldb record parse

Andrew Bartlett abartlet at samba.org
Fri Jun 30 21:35:37 UTC 2017


G'Day,

Recently we noticed that strlen() is being called twice when parsing
the DN of each entry.  It won't help much, but this patch avoids the
double-work. 

This has passed a full private autobuild.

Please review/push.

Thanks,

Andrew Bartlett
-- 
Andrew Bartlett                       http://samba.org/~abartlet/
Authentication Developer, Samba Team  http://samba.org
Samba Developer, Catalyst IT          http://catalyst.net.nz/services/samba
-------------- next part --------------
From 6a3522bf2e3b1a9491eacf6844826ad070af7b3f Mon Sep 17 00:00:00 2001
From: Andrew Bartlett <abartlet at samba.org>
Date: Fri, 30 Jun 2017 12:55:15 +1200
Subject: [PATCH] ldb_pack: use ldb_dn_from_ldb_val() and avoid a duplicate
 strlen() call

Signed-off-by: Andrew Bartlett <abartlet at samba.org>
---
 lib/ldb/common/ldb_pack.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/lib/ldb/common/ldb_pack.c b/lib/ldb/common/ldb_pack.c
index a63dd58..1f1688a 100644
--- a/lib/ldb/common/ldb_pack.c
+++ b/lib/ldb/common/ldb_pack.c
@@ -274,7 +274,10 @@ int ldb_unpack_data_only_attr_list_flags(struct ldb_context *ldb,
 		if (flags & LDB_UNPACK_DATA_FLAG_NO_DN) {
 			message->dn = NULL;
 		} else {
-			message->dn = ldb_dn_new(message, ldb, (char *)p);
+			struct ldb_val blob;
+			blob.data = discard_const_p(uint8_t, p);
+			blob.length = dn_len;
+			message->dn = ldb_dn_from_ldb_val(message, ldb, &blob);
 			if (message->dn == NULL) {
 				errno = ENOMEM;
 				goto failed;
-- 
2.9.4



More information about the samba-technical mailing list