From: Douglas Bagnall Date: Thu, 25 Jul 2019 21:49:13 +0000 (+1200) Subject: ldb: don't try to save a value that isn't there X-Git-Tag: tevent-0.10.1~151 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=54f30f2fe3f03c9640664f9a11260b093fc57a5b;p=thirdparty%2Fsamba.git ldb: don't try to save a value that isn't there BUG: https://bugzilla.samba.org/show_bug.cgi?id=14049 Signed-off-by: Douglas Bagnall Reviewed-by: Andrew Bartlett Reviewed-by: Gary Lockyer --- diff --git a/lib/ldb/common/ldb_dn.c b/lib/ldb/common/ldb_dn.c index 9b2fa966e11..a7fb0d9c443 100644 --- a/lib/ldb/common/ldb_dn.c +++ b/lib/ldb/common/ldb_dn.c @@ -697,31 +697,32 @@ static bool ldb_dn_explode(struct ldb_dn *dn) goto failed; } - /* save last element */ - if ( t ) { - /* trim back */ - d -= (p - t); - l -= (p - t); - } + if (in_value) { + /* save last element */ + if ( t ) { + /* trim back */ + d -= (p - t); + l -= (p - t); + } + + *d++ = '\0'; + /* + * This talloc_memdup() is OK with the + * +1 because *d has been set to '\0' + * just above. + */ + dn->components[dn->comp_num].value.length = l; + dn->components[dn->comp_num].value.data = + (uint8_t *)talloc_memdup(dn->components, dt, l + 1); + if ( ! dn->components[dn->comp_num].value.data) { + /* ouch */ + goto failed; + } + talloc_set_name_const(dn->components[dn->comp_num].value.data, + (const char *)dn->components[dn->comp_num].value.data); - *d++ = '\0'; - /* - * This talloc_memdup() is OK with the - * +1 because *d has been set to '\0' - * just above. - */ - dn->components[dn->comp_num].value.length = l; - dn->components[dn->comp_num].value.data = - (uint8_t *)talloc_memdup(dn->components, dt, l + 1); - if ( ! dn->components[dn->comp_num].value.data) { - /* ouch */ - goto failed; + dn->comp_num++; } - talloc_set_name_const(dn->components[dn->comp_num].value.data, - (const char *)dn->components[dn->comp_num].value.data); - - dn->comp_num++; - talloc_free(data); return true;