Ian Kent 7f83a0
autofs-5.0.6 - fix segfault in get_query_dn()
Ian Kent 7f83a0
Ian Kent 7f83a0
From: Leonardo Chiquitto <leonardo.lists@gmail.com>
Ian Kent 7f83a0
Ian Kent 7f83a0
Automount will segfault when two threads run get_query_dn()
Ian Kent 7f83a0
simultaneously and $SEARCH_BASE is defined in sysconfig.
Ian Kent 7f83a0
This happens because a thread tries to dereference ctxt->sdns
Ian Kent 7f83a0
while another thread running the same function frees the
Ian Kent 7f83a0
memory.
Ian Kent 7f83a0
Ian Kent 7f83a0
I believe we don't need to reread $SEARCH_BASE every time
Ian Kent 7f83a0
get_query_dn() is called.
Ian Kent 7f83a0
Ian Kent 7f83a0
edit: Ian Kent <raven@themaw.net>
Ian Kent 7f83a0
move the read of configured search dns to lookup_init().
Ian Kent 7f83a0
edit end
Ian Kent 7f83a0
---
Ian Kent 7f83a0
Ian Kent 7f83a0
 modules/lookup_ldap.c |   13 +++----------
Ian Kent 7f83a0
 1 file changed, 3 insertions(+), 10 deletions(-)
Ian Kent 7f83a0
Ian Kent 7f83a0
Ian Kent 7f83a0
--- autofs-5.0.6.orig/modules/lookup_ldap.c
Ian Kent 7f83a0
+++ autofs-5.0.6/modules/lookup_ldap.c
Ian Kent 7f83a0
@@ -281,7 +281,6 @@ static int get_query_dn(unsigned logopt,
Ian Kent 7f83a0
 	char buf[MAX_ERR_BUF];
Ian Kent 7f83a0
 	char *query, *dn, *qdn;
Ian Kent 7f83a0
 	LDAPMessage *result, *e;
Ian Kent 7f83a0
-	struct ldap_searchdn *sdns = NULL;
Ian Kent 7f83a0
 	char *attrs[2];
Ian Kent 7f83a0
 	struct berval **value;
Ian Kent 7f83a0
 	int scope;
Ian Kent 7f83a0
@@ -330,15 +329,6 @@ static int get_query_dn(unsigned logopt,
Ian Kent 7f83a0
 		scope = LDAP_SCOPE_SUBTREE;
Ian Kent 7f83a0
 	}
Ian Kent 7f83a0
 
Ian Kent 7f83a0
-	if (!ctxt->base) {
Ian Kent 7f83a0
-		sdns = defaults_get_searchdns();
Ian Kent 7f83a0
-		if (sdns) {
Ian Kent 7f83a0
-			if (ctxt->sdns)
Ian Kent 7f83a0
-				defaults_free_searchdns(ctxt->sdns);
Ian Kent 7f83a0
-			ctxt->sdns = sdns;
Ian Kent 7f83a0
-		}
Ian Kent 7f83a0
-	}
Ian Kent 7f83a0
-
Ian Kent 7f83a0
 	dn = NULL;
Ian Kent 7f83a0
 	if (!ctxt->sdns) {
Ian Kent 7f83a0
 		rv = ldap_search_s(ldap, ctxt->base,
Ian Kent 7f83a0
@@ -1467,6 +1457,9 @@ int lookup_init(const char *mapfmt, int
Ian Kent 7f83a0
 		return 1;
Ian Kent 7f83a0
 	}
Ian Kent 7f83a0
 
Ian Kent 7f83a0
+	if (!ctxt->base)
Ian Kent 7f83a0
+		ctxt->sdns = defaults_get_searchdns();
Ian Kent 7f83a0
+
Ian Kent 7f83a0
 	ctxt->timeout = defaults_get_ldap_timeout();
Ian Kent 7f83a0
 	ctxt->network_timeout = defaults_get_ldap_network_timeout();
Ian Kent 7f83a0