autofs-5.1.2 - fix offset mount location multiple expansion

When parsing an offset map entry mount location it shouldn't be
expanded because it will have already been dequoted before being
added to the map entry cache when it was first parsed.

Expanding it again can lead to inconsistent behaviour between
the expansion of simple map entry locations and offset locations
that have had quoting removed as part of the initial parse.

Signed-off-by: Ian Kent <raven@themaw.net>
diff --git a/CHANGELOG b/CHANGELOG
index 1ea69d5..46487f1 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -59,6 +59,7 @@
 - fix work around sss startup delay.
 - fix invalid reference in remount_active_mount().
 - use malloc for expanded map location.
+- fix offset mount location multiple expansion.
 
 15/06/2016 autofs-5.1.2
 =======================
diff --git a/modules/parse_sun.c b/modules/parse_sun.c
index 8955c84..536a9bc 100644
--- a/modules/parse_sun.c
+++ b/modules/parse_sun.c
@@ -1297,6 +1297,30 @@
 
 	pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cur_state);
 
+	/* Offset map entries have been expanded already, avoid expanding
+	 * them again so that the quote handling is consistent between map
+	 * entry locations and (previously expanded) offset map entry
+	 * locations.
+	 */
+	if (*name == '/') {
+		cache_readlock(mc);
+		me = cache_lookup_distinct(mc, name);
+		if (me && me->multi && me->multi != me) {
+			cache_unlock(mc);
+			mapent_len = strlen(mapent) + 1;
+			pmapent = malloc(mapent_len + 1);
+			if (!pmapent) {
+				char *estr = strerror_r(errno, buf, MAX_ERR_BUF);
+				logerr(MODPREFIX "malloc: %s", estr);
+				return 1;
+			}
+			memset(pmapent, 0, mapent_len + 1);
+			strcpy(pmapent, mapent);
+			goto dont_expand;
+		}
+		cache_unlock(mc);
+	}
+
 	macro_lock();
 	ctxt->subst = addstdenv(ctxt->subst, NULL);
 
@@ -1313,6 +1337,7 @@
 	ctxt->subst = removestdenv(ctxt->subst, NULL);
 	macro_unlock();
 
+dont_expand:
 	pthread_setcancelstate(cur_state, NULL);
 
 	debug(ap->logopt, MODPREFIX "expanded entry: %s", pmapent);