From 4fb23630ba3f5e17f41c40b90f423a20987db594 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Fri, 17 Jun 2016 13:28:59 +1200 Subject: [PATCH] ldb: Do not allocate the extended DN name The name must be a hard-coded value from struct ldb_dn_extended_syntax so just point to that constant pointer Signed-off-by: Andrew Bartlett Reviewed-by: Garming Sam --- lib/ldb/common/ldb_dn.c | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/lib/ldb/common/ldb_dn.c b/lib/ldb/common/ldb_dn.c index ab78776368e..3fa5ab57056 100644 --- a/lib/ldb/common/ldb_dn.c +++ b/lib/ldb/common/ldb_dn.c @@ -54,7 +54,7 @@ struct ldb_dn_component { struct ldb_dn_ext_component { - char *name; + const char *name; struct ldb_val value; }; @@ -408,11 +408,7 @@ static bool ldb_dn_explode(struct ldb_dn *dn) goto failed; } - dn->ext_components[dn->ext_comp_num].name = talloc_strdup(dn->ext_components, ex_name); - if (!dn->ext_components[dn->ext_comp_num].name) { - /* ouch */ - goto failed; - } + dn->ext_components[dn->ext_comp_num].name = ext_syntax->name; ret = ext_syntax->read_fn(dn->ldb, dn->ext_components, &ex_val, &dn->ext_components[dn->ext_comp_num].value); if (ret != LDB_SUCCESS) { @@ -1990,12 +1986,14 @@ int ldb_dn_set_extended_component(struct ldb_dn *dn, struct ldb_dn_ext_component *p; unsigned int i; struct ldb_val v2; - + const struct ldb_dn_extended_syntax *ext_syntax; + if ( ! ldb_dn_validate(dn)) { return LDB_ERR_OTHER; } - if (!ldb_dn_extended_syntax_by_name(dn->ldb, name)) { + ext_syntax = ldb_dn_extended_syntax_by_name(dn->ldb, name); + if (ext_syntax == NULL) { /* We don't know how to handle this type of thing */ return LDB_ERR_INVALID_DN_SYNTAX; } @@ -2006,10 +2004,8 @@ int ldb_dn_set_extended_component(struct ldb_dn *dn, dn->ext_components[i].value = ldb_val_dup(dn->ext_components, val); - dn->ext_components[i].name = - talloc_strdup(dn->ext_components, name); - if (!dn->ext_components[i].name || - !dn->ext_components[i].value.data) { + dn->ext_components[i].name = ext_syntax->name; + if (!dn->ext_components[i].value.data) { ldb_dn_mark_invalid(dn); return LDB_ERR_OPERATIONS_ERROR; } @@ -2170,7 +2166,6 @@ bool ldb_dn_minimise(struct ldb_dn *dn) */ for (i = 1; i < dn->ext_comp_num; i++) { - LDB_FREE(dn->ext_components[i].name); LDB_FREE(dn->ext_components[i].value.data); } dn->ext_comp_num = 1; -- 2.47.2