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

29d2b9
autofs-5.1.7 - refactor lookup_prune_one_cache() a bit
29d2b9
29d2b9
From: Ian Kent <raven@themaw.net>
29d2b9
29d2b9
Coverity: use: Using an unreliable value of "me" inside the second locked
29d2b9
	  section.
29d2b9
29d2b9
Change lookup_prune_one_cache() a little, move the location the next
29d2b9
key is set (before releasing the lock) and add a comment explaining
29d2b9
why we don't care about the side effects of the read lock release/
29d2b9
write lock aquire/write lock release/read lock reaquire.
29d2b9
29d2b9
Signed-off-by: Ian Kent <raven@themaw.net>
29d2b9
---
29d2b9
 CHANGELOG       |    1 +
29d2b9
 daemon/lookup.c |   20 +++++++++++++++++++-
29d2b9
 2 files changed, 20 insertions(+), 1 deletion(-)
29d2b9
29d2b9
diff --git a/CHANGELOG b/CHANGELOG
29d2b9
index 81461978..b79aebc8 100644
29d2b9
--- a/CHANGELOG
29d2b9
+++ b/CHANGELOG
29d2b9
@@ -63,6 +63,7 @@
29d2b9
 - fix arg not used in error print.
29d2b9
 - fix missing lock release in mount_subtree().
29d2b9
 - fix double free in parse_mapent().
29d2b9
+- refactor lookup_prune_one_cache() a bit.
29d2b9
 
29d2b9
 25/01/2021 autofs-5.1.7
29d2b9
 - make bind mounts propagation slave by default.
29d2b9
diff --git a/daemon/lookup.c b/daemon/lookup.c
29d2b9
index 32dbc24d..3e9722e4 100644
29d2b9
--- a/daemon/lookup.c
29d2b9
+++ b/daemon/lookup.c
29d2b9
@@ -1375,7 +1375,6 @@ void lookup_prune_one_cache(struct autofs_point *ap, struct mapent_cache *mc, ti
29d2b9
 		}
29d2b9
 
29d2b9
 		key = strdup(me->key);
29d2b9
-		me = cache_enumerate(mc, me);
29d2b9
 		/* Don't consider any entries with a wildcard */
29d2b9
 		if (!key || strchr(key, '*')) {
29d2b9
 			if (key)
29d2b9
@@ -1422,6 +1421,7 @@ void lookup_prune_one_cache(struct autofs_point *ap, struct mapent_cache *mc, ti
29d2b9
 		if (valid)
29d2b9
 			cache_unlock(valid->mc);
29d2b9
 
29d2b9
+		me = cache_enumerate(mc, me);
29d2b9
 		if (me)
29d2b9
 			next_key = strdup(me->key);
29d2b9
 
29d2b9
@@ -1456,6 +1456,24 @@ void lookup_prune_one_cache(struct autofs_point *ap, struct mapent_cache *mc, ti
29d2b9
 next:
29d2b9
 		cache_readlock(mc);
29d2b9
 		if (next_key) {
29d2b9
+			/* The lock release and reaquire above can mean
29d2b9
+			 * a number of things could happen.
29d2b9
+			 *
29d2b9
+			 * First, mapents could be added between the
29d2b9
+			 * current mapent and the mapent of next_key.
29d2b9
+			 * Don't care about that because there's no
29d2b9
+			 * need to prune newly added entries.
29d2b9
+			 *
29d2b9
+			 * Second, the next mapent data could have
29d2b9
+			 * changed. Don't care about that either since
29d2b9
+			 * we are looking to prune stale map entries
29d2b9
+			 * and don't care when they become stale.
29d2b9
+			 *
29d2b9
+			 * Finally, the mapent of next_key could have
29d2b9
+			 * gone away. Again don't care about this either,
29d2b9
+			 * the loop will exit prematurely so just wait
29d2b9
+			 * until the next prune and try again.
29d2b9
+			 */
29d2b9
 			me = cache_lookup_distinct(mc, next_key);
29d2b9
 			free(next_key);
29d2b9
 		}