Blame SOURCES/autofs-5.1.0-fix-mount-as-you-go-offset-selection.patch

304803
autofs-5.1.0 - fix mount as you go offset selection
304803
304803
From: Ian Kent <raven@themaw.net>
304803
304803
The function cache_get_offset() returns offsets to be mounted that
304803
are within the current current subtree for the mount-as-you-go
304803
functionality used for nested multi-mount map entries.
304803
304803
However, the function was returning offsets from the subree below
304803
nesting points which prevented the mount at the containing nesting
304803
point from being mounted. This is because the kernel will see a
304803
non-empty directory and conclude it isn't a mount point.
304803
---
304803
 CHANGELOG   |    1 +
304803
 lib/cache.c |   27 ++++++++++++++++++++++++---
304803
 2 files changed, 25 insertions(+), 3 deletions(-)
304803
304803
--- autofs-5.0.7.orig/CHANGELOG
304803
+++ autofs-5.0.7/CHANGELOG
304803
@@ -168,6 +168,7 @@
304803
 - handle duplicates in multi mounts.
304803
 - fix macro usage in lookup_program.c.
304803
 - remove unused offset handling code.
304803
+- fix mount as you go offset selection.
304803
 
304803
 25/07/2012 autofs-5.0.7
304803
 =======================
304803
--- autofs-5.0.7.orig/lib/cache.c
304803
+++ autofs-5.0.7/lib/cache.c
304803
@@ -1183,7 +1183,6 @@ struct mapent *cache_enumerate(struct ma
304803
  * Get each offset from list head under prefix.
304803
  * Maintain traversal current position in pos for subsequent calls. 
304803
  * Return each offset into offset.
304803
- * TODO: length check on offset.
304803
  */
304803
 /* cache must be read locked by caller */
304803
 char *cache_get_offset(const char *prefix, char *offset, int start,
304803
@@ -1212,6 +1211,9 @@ char *cache_get_offset(const char *prefi
304803
 			continue;
304803
 
304803
 		if (!strncmp(prefix, offset_start, plen)) {
304803
+			struct mapent *np = NULL;
304803
+			char pe[PATH_MAX + 1];
304803
+
304803
 			/* "/" doesn't count for root offset */
304803
 			if (plen == 1)
304803
 				pstart = &offset_start[plen - 1];
304803
@@ -1224,7 +1226,24 @@ char *cache_get_offset(const char *prefi
304803
 
304803
 			/* get next offset */
304803
 			pend = pstart;
304803
-			while (*pend++) ;
304803
+			while (*pend++) {
304803
+				size_t nest_pt_offset;
304803
+
304803
+				if (*pend != '/')
304803
+					continue;
304803
+
304803
+				nest_pt_offset = start + pend - pstart;
304803
+				if (plen > 1)
304803
+					nest_pt_offset += plen;
304803
+				strcpy(pe, this->key);
304803
+				pe[nest_pt_offset] = '\0';
304803
+
304803
+				np = cache_lookup_distinct(this->mc, pe);
304803
+				if (np)
304803
+					break;
304803
+			}
304803
+			if (np)
304803
+				continue;
304803
 			len = pend - pstart - 1;
304803
 			strncpy(offset, pstart, len);
304803
 			offset[len] ='\0';
304803
@@ -1257,7 +1276,9 @@ char *cache_get_offset(const char *prefi
304803
 			break;
304803
 
304803
 		/* compare offset */
304803
-		if (pstart[len] != '/' || strncmp(offset, pstart, len))
304803
+		if (pstart[len] != '/' ||
304803
+		    strlen(pstart) != len ||
304803
+		    strncmp(offset, pstart, len))
304803
 			break;
304803
 
304803
 		*pos = next;