Blame SOURCES/autofs-5.0.7-fix-potential-null-dereference-in-lookup_mount.patch

304803
autofs-5.0.7 - fix potential null dereference in lookup_mount()
304803
304803
From: Ian Kent <raven@themaw.net>
304803
304803
Updating a negative cache entry should always find an entry but the entry
304803
lookup return isn't checked and probably should be.
304803
304803
Since this code is duplicated in several modules add it as a function to
304803
the cache handling code.
304803
---
304803
 include/automount.h   |    1 +
304803
 lib/cache.c           |   20 ++++++++++++++++++++
304803
 modules/lookup_file.c |   11 +----------
304803
 modules/lookup_ldap.c |   12 +-----------
304803
 modules/lookup_sss.c  |   12 +-----------
304803
 modules/lookup_yp.c   |   12 ++----------
304803
 6 files changed, 26 insertions(+), 42 deletions(-)
304803
304803
diff --git a/include/automount.h b/include/automount.h
304803
index 6ced842..71787a5 100644
304803
--- a/include/automount.h
304803
+++ b/include/automount.h
304803
@@ -189,6 +189,7 @@ struct mapent *cache_lookup_offset(const char *prefix, const char *offset, int s
304803
 struct mapent *cache_partial_match(struct mapent_cache *mc, const char *prefix);
304803
 int cache_add(struct mapent_cache *mc, struct map_source *ms, const char *key, const char *mapent, time_t age);
304803
 int cache_update_offset(struct mapent_cache *mc, const char *mkey, const char *key, const char *mapent, time_t age);
304803
+void cache_update_negative(struct mapent_cache *mc, struct map_source *ms, const char *key, time_t timeout);
304803
 int cache_set_parents(struct mapent *mm);
304803
 int cache_update(struct mapent_cache *mc, struct map_source *ms, const char *key, const char *mapent, time_t age);
304803
 int cache_delete(struct mapent_cache *mc, const char *key);
304803
diff --git a/lib/cache.c b/lib/cache.c
304803
index ecace4a..be4917b 100644
304803
--- a/lib/cache.c
304803
+++ b/lib/cache.c
304803
@@ -680,6 +680,26 @@ done:
304803
 	return ret; 
304803
 }
304803
 
304803
+void cache_update_negative(struct mapent_cache *mc,
304803
+			   struct map_source *ms, const char *key,
304803
+			   time_t timeout)
304803
+{
304803
+	time_t now = time(NULL);
304803
+	struct mapent *me;
304803
+	int rv = CHE_OK;
304803
+
304803
+	me = cache_lookup_distinct(mc, key);
304803
+	if (!me)
304803
+		rv = cache_update(mc, ms, key, NULL, now);
304803
+	if (rv != CHE_FAIL) {
304803
+		me = cache_lookup_distinct(mc, key);
304803
+		if (me)
304803
+			me->status = now + timeout;
304803
+	}
304803
+	return;
304803
+}
304803
+
304803
+
304803
 static struct mapent *get_parent(const char *key, struct list_head *head, struct list_head **pos)
304803
 {
304803
 	struct list_head *next;
304803
diff --git a/modules/lookup_file.c b/modules/lookup_file.c
304803
index 2836996..4b4ee89 100644
304803
--- a/modules/lookup_file.c
304803
+++ b/modules/lookup_file.c
304803
@@ -1130,17 +1130,8 @@ do_cache_lookup:
304803
 	ret = ctxt->parse->parse_mount(ap, key, key_len,
304803
 				       mapent, ctxt->parse->context);
304803
 	if (ret) {
304803
-		time_t now = time(NULL);
304803
-		int rv = CHE_OK;
304803
-
304803
 		cache_writelock(mc);
304803
-		me = cache_lookup_distinct(mc, key);
304803
-		if (!me)
304803
-			rv = cache_update(mc, source, key, NULL, now);
304803
-		if (rv != CHE_FAIL) {
304803
-			me = cache_lookup_distinct(mc, key);
304803
-			me->status = now + ap->negative_timeout;
304803
-		}
304803
+		cache_update_negative(mc, source, key, ap->negative_timeout);
304803
 		cache_unlock(mc);
304803
 		return NSS_STATUS_TRYAGAIN;
304803
 	}
304803
diff --git a/modules/lookup_ldap.c b/modules/lookup_ldap.c
304803
index a59de92..26481a8 100644
304803
--- a/modules/lookup_ldap.c
304803
+++ b/modules/lookup_ldap.c
304803
@@ -3011,18 +3011,8 @@ int lookup_mount(struct autofs_point *ap, const char *name, int name_len, void *
304803
 	ret = ctxt->parse->parse_mount(ap, key, key_len,
304803
 				       mapent, ctxt->parse->context);
304803
 	if (ret) {
304803
-		time_t now = time(NULL);
304803
-		int rv = CHE_OK;
304803
-
304803
-		/* Record the the mount fail in the cache */
304803
 		cache_writelock(mc);
304803
-		me = cache_lookup_distinct(mc, key);
304803
-		if (!me)
304803
-			rv = cache_update(mc, source, key, NULL, now);
304803
-		if (rv != CHE_FAIL) {
304803
-			me = cache_lookup_distinct(mc, key);
304803
-			me->status = now + ap->negative_timeout;
304803
-		}
304803
+		cache_update_negative(mc, source, key, ap->negative_timeout);
304803
 		cache_unlock(mc);
304803
 		return NSS_STATUS_TRYAGAIN;
304803
 	}
304803
diff --git a/modules/lookup_sss.c b/modules/lookup_sss.c
304803
index 5c2ed0a..1fe740b 100644
304803
--- a/modules/lookup_sss.c
304803
+++ b/modules/lookup_sss.c
304803
@@ -672,18 +672,8 @@ int lookup_mount(struct autofs_point *ap, const char *name, int name_len, void *
304803
 	ret = ctxt->parse->parse_mount(ap, key, key_len,
304803
 				       mapent, ctxt->parse->context);
304803
 	if (ret) {
304803
-		time_t now = time(NULL);
304803
-		int rv = CHE_OK;
304803
-
304803
-		/* Record the the mount fail in the cache */
304803
 		cache_writelock(mc);
304803
-		me = cache_lookup_distinct(mc, key);
304803
-		if (!me)
304803
-			rv = cache_update(mc, source, key, NULL, now);
304803
-		if (rv != CHE_FAIL) {
304803
-			me = cache_lookup_distinct(mc, key);
304803
-			me->status = now + ap->negative_timeout;
304803
-		}
304803
+		cache_update_negative(mc, source, key, ap->negative_timeout);
304803
 		cache_unlock(mc);
304803
 		return NSS_STATUS_TRYAGAIN;
304803
 	}
304803
diff --git a/modules/lookup_yp.c b/modules/lookup_yp.c
304803
index a716e1f..e99e3c0 100644
304803
--- a/modules/lookup_yp.c
304803
+++ b/modules/lookup_yp.c
304803
@@ -698,18 +698,10 @@ int lookup_mount(struct autofs_point *ap, const char *name, int name_len, void *
304803
 		ret = ctxt->parse->parse_mount(ap, key, key_len,
304803
 					       mapent, ctxt->parse->context);
304803
 		if (ret) {
304803
-			time_t now = time(NULL);
304803
-			int rv = CHE_OK;
304803
-
304803
 			cache_writelock(mc);
304803
-			me = cache_lookup_distinct(mc, key);
304803
-			if (!me)
304803
-				rv = cache_update(mc, source, key, NULL, now);
304803
-			if (rv != CHE_FAIL) {
304803
-				me = cache_lookup_distinct(mc, key);
304803
-				me->status = now + ap->negative_timeout;
304803
-			}
304803
+			cache_update_negative(mc, source, key, ap->negative_timeout);
304803
 			cache_unlock(mc);
304803
+			return NSS_STATUS_TRYAGAIN;
304803
 		}
304803
 	 }
304803