>From d5bea897a876063ad8e9e57f8355addc9549c430 Mon Sep 17 00:00:00 2001
From: Stephen Gallagher <sgallagh@redhat.com>
Date: Wed, 26 Sep 2012 11:00:16 -0400
Subject: [PATCH] LDAP: Handle empty namingContexts values safely

Certain LDAP servers can return an empty string as the value of
namingContexts. We need to treat these as NULL so that we can fail
gracefully.
---
 src/providers/ldap/sdap.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/src/providers/ldap/sdap.c b/src/providers/ldap/sdap.c
index 5c4a005570a45b349f9adf827e3b797b5e720d2a..cdc8b1f18cb38b43a83d734bb5237d5379831b53 100644
--- a/src/providers/ldap/sdap.c
+++ b/src/providers/ldap/sdap.c
@@ -742,6 +742,14 @@ static char *get_naming_context(TALLOC_CTX *mem_ctx,
         }
     }
 
+    /* Some directory servers such as Novell eDirectory will return
+     * a zero-length namingContexts value in some situations. In this
+     * case, we should return it as NULL so things fail gracefully.
+     */
+    if (naming_context[0] == '\0') {
+        talloc_zfree(naming_context);
+    }
+
     return naming_context;
 }
 
-- 
1.7.12

