ldb_dn_new_fmt() has a bug and cannot take a NULL memory context

This hack just creates a tmp_ctx to pass to the ldb routine and then
steals it back onto the memctx before returning it.
From 5daeba168a08661aa1104b2c50f73d4c8a4a200d Mon Sep 17 00:00:00 2001
From: Stephen Gallagher <sgall...@redhat.com>
Date: Fri, 8 Jul 2011 12:23:34 -0400
Subject: [PATCH 9/9] Allow NULL memctx in sysdb_custom_subtree_dn

ldb_dn_new_fmt() has a bug and cannot take a NULL memory context
---
 src/db/sysdb.c |   14 +++++++++++---
 1 files changed, 11 insertions(+), 3 deletions(-)

diff --git a/src/db/sysdb.c b/src/db/sysdb.c
index ffe9ff7743ca6047926e8dcad0262e6f6d723c58..8165e923c519e2092b14d2638eb64b7751a283f9 100644
--- a/src/db/sysdb.c
+++ b/src/db/sysdb.c
@@ -96,15 +96,23 @@ struct ldb_dn *sysdb_custom_subtree_dn(struct sysdb_ctx *ctx, void *memctx,
     errno_t ret;
     char *clean_subtree;
     struct ldb_dn *dn = NULL;
+    TALLOC_CTX *tmp_ctx;
 
-    ret = sysdb_dn_sanitize(NULL, subtree_name, &clean_subtree);
+    tmp_ctx = talloc_new(memctx);
+    if (!tmp_ctx) return NULL;
+
+    ret = sysdb_dn_sanitize(tmp_ctx, subtree_name, &clean_subtree);
     if (ret != EOK) {
+        talloc_free(tmp_ctx);
         return NULL;
     }
 
-    dn = ldb_dn_new_fmt(memctx, ctx->ldb, SYSDB_TMPL_CUSTOM_SUBTREE,
+    dn = ldb_dn_new_fmt(tmp_ctx, ctx->ldb, SYSDB_TMPL_CUSTOM_SUBTREE,
                         clean_subtree, domain);
-    talloc_free(clean_subtree);
+    if (dn) {
+        talloc_steal(memctx, dn);
+    }
+    talloc_free(tmp_ctx);
 
     return dn;
 }
-- 
1.7.6

Attachment: signature.asc
Description: This is a digitally signed message part

_______________________________________________
sssd-devel mailing list
sssd-devel@lists.fedorahosted.org
https://fedorahosted.org/mailman/listinfo/sssd-devel

Reply via email to