From 4cd16dde148662700311501e62ba3ee9bf80765a Mon Sep 17 00:00:00 2001 From: Kamen Mazdrashki Date: Wed, 1 Dec 2010 11:04:19 +0200 Subject: s4-ranged_result.c: Fix memory context for ranged attributes handling Pair-Programmed-With: Zahari Zahariev Autobuild-User: Kamen Mazdrashki Autobuild-Date: Wed Dec 1 11:45:48 CET 2010 on sn-devel-104 --- source4/dsdb/samdb/ldb_modules/ranged_results.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) (limited to 'source4/dsdb/samdb/ldb_modules') diff --git a/source4/dsdb/samdb/ldb_modules/ranged_results.c b/source4/dsdb/samdb/ldb_modules/ranged_results.c index b3e79d0881..f8e8db60b7 100644 --- a/source4/dsdb/samdb/ldb_modules/ranged_results.c +++ b/source4/dsdb/samdb/ldb_modules/ranged_results.c @@ -59,6 +59,7 @@ static int rr_search_callback(struct ldb_request *req, struct ldb_reply *ares) struct ldb_context *ldb; struct rr_context *ac; unsigned int i, j; + TALLOC_CTX *temp_ctx; ac = talloc_get_type(req->context, struct rr_context); ldb = ldb_module_get_ctx(ac->module); @@ -83,6 +84,13 @@ static int rr_search_callback(struct ldb_request *req, struct ldb_reply *ares) /* LDB_REPLY_ENTRY */ + temp_ctx = talloc_new(ac->req); + if (!temp_ctx) { + ldb_module_oom(ac->module); + return ldb_module_done(ac->req, NULL, NULL, + LDB_ERR_OPERATIONS_ERROR); + } + /* Find those that are range requests from the attribute list */ for (i = 0; ac->req->op.search.attrs[i]; i++) { char *p, *new_attr; @@ -90,6 +98,7 @@ static int rr_search_callback(struct ldb_request *req, struct ldb_reply *ares) unsigned int start, end, orig_num_values; struct ldb_message_element *el; struct ldb_val *orig_values; + p = strchr(ac->req->op.search.attrs[i], ';'); if (!p) { continue; @@ -104,7 +113,7 @@ static int rr_search_callback(struct ldb_request *req, struct ldb_reply *ares) continue; } } - new_attr = talloc_strndup(ac->req, + new_attr = talloc_strndup(temp_ctx, ac->req->op.search.attrs[i], (size_t)(p - ac->req->op.search.attrs[i])); @@ -124,7 +133,7 @@ static int rr_search_callback(struct ldb_request *req, struct ldb_reply *ares) end_str = "*"; end = el->num_values - 1; } else { - end_str = talloc_asprintf(el, "%u", end); + end_str = talloc_asprintf(temp_ctx, "%u", end); if (!end_str) { ldb_oom(ldb); return ldb_module_done(ac->req, NULL, NULL, @@ -148,7 +157,7 @@ static int rr_search_callback(struct ldb_request *req, struct ldb_reply *ares) el->num_values = 0; - el->values = talloc_array(el, struct ldb_val, (end - start) + 1); + el->values = talloc_array(ares->message->elements, struct ldb_val, (end - start) + 1); if (!el->values) { ldb_oom(ldb); return ldb_module_done(ac->req, NULL, NULL, @@ -159,7 +168,7 @@ static int rr_search_callback(struct ldb_request *req, struct ldb_reply *ares) el->num_values++; } } - el->name = talloc_asprintf(el, "%s;range=%u-%s", el->name, start, end_str); + el->name = talloc_asprintf(el->values, "%s;range=%u-%s", el->name, start, end_str); if (!el->name) { ldb_oom(ldb); return ldb_module_done(ac->req, NULL, NULL, @@ -167,6 +176,8 @@ static int rr_search_callback(struct ldb_request *req, struct ldb_reply *ares) } } + talloc_free(temp_ctx); + return ldb_module_send_entry(ac->req, ares->message, ares->controls); } -- cgit