autofs-5.0.5 - mapent becomes negative during lookup

From: Ian Kent <raven@themaw.net>

During a mount request it is possible for a mapent to become negative
between the time it is checked on entry and when we fetch the mount
location information. This is because we drop the cache lock after
the initial check and take it back again before getting the location
information.
---

 CHANGELOG                |    1 +
 modules/lookup_file.c    |    2 +-
 modules/lookup_ldap.c    |    2 +-
 modules/lookup_nisplus.c |    2 +-
 modules/lookup_yp.c      |    2 +-
 5 files changed, 5 insertions(+), 4 deletions(-)


diff --git a/CHANGELOG b/CHANGELOG
index bfee5de..4788f44 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -40,6 +40,7 @@
 - dont check null cache on expire.
 - fix null cache race.
 - fix cache_init() on source re-read.
+- fix mapent becomes negative during lookup.
 
 03/09/2009 autofs-5.0.5
 -----------------------
diff --git a/modules/lookup_file.c b/modules/lookup_file.c
index 676be9e..b207947 100644
--- a/modules/lookup_file.c
+++ b/modules/lookup_file.c
@@ -1047,7 +1047,7 @@ do_cache_lookup:
 		if (!me)
 			me = cache_lookup_distinct(mc, "*");
 	}
-	if (me && (me->source == source || *me->key == '/')) {
+	if (me && me->mapent && (me->source == source || *me->key == '/')) {
 		pthread_cleanup_push(cache_lock_cleanup, mc);
 		strcpy(mapent_buf, me->mapent);
 		mapent = mapent_buf;
diff --git a/modules/lookup_ldap.c b/modules/lookup_ldap.c
index f02d0dc..9aac960 100644
--- a/modules/lookup_ldap.c
+++ b/modules/lookup_ldap.c
@@ -2872,7 +2872,7 @@ int lookup_mount(struct autofs_point *ap, const char *name, int name_len, void *
 		if (!me)
 			me = cache_lookup_distinct(mc, "*");
 	}
-	if (me && (me->source == source || *me->key == '/')) {
+	if (me && me->mapent && (me->source == source || *me->key == '/')) {
 		strcpy(mapent_buf, me->mapent);
 		mapent = mapent_buf;
 	}
diff --git a/modules/lookup_nisplus.c b/modules/lookup_nisplus.c
index 9b7941a..bcd5973 100644
--- a/modules/lookup_nisplus.c
+++ b/modules/lookup_nisplus.c
@@ -569,7 +569,7 @@ int lookup_mount(struct autofs_point *ap, const char *name, int name_len, void *
 		if (!me)
 			me = cache_lookup_distinct(mc, "*");
 	}
-	if (me && (me->source == source || *me->key == '/')) {
+	if (me && me->mapent && (me->source == source || *me->key == '/')) {
 		mapent_len = strlen(me->mapent);
 		mapent = malloc(mapent_len + 1);
 		strcpy(mapent, me->mapent);
diff --git a/modules/lookup_yp.c b/modules/lookup_yp.c
index fb0ae9f..9d35be5 100644
--- a/modules/lookup_yp.c
+++ b/modules/lookup_yp.c
@@ -670,7 +670,7 @@ int lookup_mount(struct autofs_point *ap, const char *name, int name_len, void *
 		if (!me)
 			me = cache_lookup_distinct(mc, "*");
 	}
-	if (me && (me->source == source || *me->key == '/')) {
+	if (me && me->mapent && (me->source == source || *me->key == '/')) {
 		mapent_len = strlen(me->mapent);
 		mapent = alloca(mapent_len + 1);
 		strcpy(mapent, me->mapent);