Blame SOURCES/autofs-5.1.7-refactor-lookup_prune_one_cache-a-bit.patch

beb904
autofs-5.1.7 - refactor lookup_prune_one_cache() a bit
beb904
beb904
From: Ian Kent <raven@themaw.net>
beb904
beb904
Coverity: use: Using an unreliable value of "me" inside the second locked
beb904
	  section.
beb904
beb904
Change lookup_prune_one_cache() a little, move the location the next
beb904
key is set (before releasing the lock) and add a comment explaining
beb904
why we don't care about the side effects of the read lock release/
beb904
write lock aquire/write lock release/read lock reaquire.
beb904
beb904
Signed-off-by: Ian Kent <raven@themaw.net>
beb904
---
beb904
 CHANGELOG       |    1 +
beb904
 daemon/lookup.c |   20 +++++++++++++++++++-
beb904
 2 files changed, 20 insertions(+), 1 deletion(-)
beb904
beb904
--- autofs-5.1.4.orig/CHANGELOG
beb904
+++ autofs-5.1.4/CHANGELOG
beb904
@@ -63,6 +63,7 @@
beb904
 - fix arg not used in error print.
beb904
 - fix missing lock release in mount_subtree().
beb904
 - fix double free in parse_mapent().
beb904
+- refactor lookup_prune_one_cache() a bit.
beb904
 
beb904
 xx/xx/2018 autofs-5.1.5
beb904
 - fix flag file permission.
beb904
--- autofs-5.1.4.orig/daemon/lookup.c
beb904
+++ autofs-5.1.4/daemon/lookup.c
beb904
@@ -1383,7 +1383,6 @@ void lookup_prune_one_cache(struct autof
beb904
 		}
beb904
 
beb904
 		key = strdup(me->key);
beb904
-		me = cache_enumerate(mc, me);
beb904
 		/* Don't consider any entries with a wildcard */
beb904
 		if (!key || strchr(key, '*')) {
beb904
 			if (key)
beb904
@@ -1430,6 +1429,7 @@ void lookup_prune_one_cache(struct autof
beb904
 		if (valid)
beb904
 			cache_unlock(valid->mc);
beb904
 
beb904
+		me = cache_enumerate(mc, me);
beb904
 		if (me)
beb904
 			next_key = strdup(me->key);
beb904
 
beb904
@@ -1464,6 +1464,24 @@ void lookup_prune_one_cache(struct autof
beb904
 next:
beb904
 		cache_readlock(mc);
beb904
 		if (next_key) {
beb904
+			/* The lock release and reaquire above can mean
beb904
+			 * a number of things could happen.
beb904
+			 *
beb904
+			 * First, mapents could be added between the
beb904
+			 * current mapent and the mapent of next_key.
beb904
+			 * Don't care about that because there's no
beb904
+			 * need to prune newly added entries.
beb904
+			 *
beb904
+			 * Second, the next mapent data could have
beb904
+			 * changed. Don't care about that either since
beb904
+			 * we are looking to prune stale map entries
beb904
+			 * and don't care when they become stale.
beb904
+			 *
beb904
+			 * Finally, the mapent of next_key could have
beb904
+			 * gone away. Again don't care about this either,
beb904
+			 * the loop will exit prematurely so just wait
beb904
+			 * until the next prune and try again.
beb904
+			 */
beb904
 			me = cache_lookup_distinct(mc, next_key);
beb904
 			free(next_key);
beb904
 		}