Blame SOURCES/autofs-5.1.0-fix-incorrect-check-in-parse_mount.patch

4d476f
autofs-5.1.0 - fix incorrect check in parse_mount()
4d476f
4d476f
From: Ian Kent <ikent@redhat.com>
4d476f
4d476f
The change to allow the use of the hosts map in map entries introduced
4d476f
an invalid check into parse_mount(). The case attempts to check the
4d476f
contents of an options string that is always invalid for the return
4d476f
value case in which it is checked, not to mention the check itself is
4d476f
incorrect.
4d476f
---
4d476f
 CHANGELOG           |    1 
4d476f
 modules/parse_sun.c |   70 ++++++++++++++++++++++++++++++++--------------------
4d476f
 2 files changed, 45 insertions(+), 26 deletions(-)
4d476f
4d476f
--- autofs-5.0.7.orig/CHANGELOG
4d476f
+++ autofs-5.0.7/CHANGELOG
4d476f
@@ -164,6 +164,7 @@
4d476f
 - dont add wildcard to negative cache.
4d476f
 - add a prefix to program map stdvars.
4d476f
 - add config option to force use of program map stdvars.
4d476f
+- fix incorrect check in parse_mount().
4d476f
 
4d476f
 25/07/2012 autofs-5.0.7
4d476f
 =======================
4d476f
--- autofs-5.0.7.orig/modules/parse_sun.c
4d476f
+++ autofs-5.0.7/modules/parse_sun.c
4d476f
@@ -756,6 +756,8 @@ update_offset_entry(struct autofs_point
4d476f
 
4d476f
 	mc = source->mc;
4d476f
 
4d476f
+	memset(m_mapent, 0, MAPENT_MAX_LEN + 1);
4d476f
+
4d476f
 	/* Internal hosts map may have loc == NULL */
4d476f
 	if (!*path) {
4d476f
 		error(ap->logopt,
4d476f
@@ -782,7 +784,7 @@ update_offset_entry(struct autofs_point
4d476f
 	if (*myoptions)
4d476f
 		m_options_len = strlen(myoptions) + 2;
4d476f
 
4d476f
-	m_mapent_len = strlen(loc);
4d476f
+	m_mapent_len = loc ? strlen(loc) : 0;
4d476f
 	if (m_mapent_len + m_options_len > MAPENT_MAX_LEN) {
4d476f
 		error(ap->logopt, MODPREFIX "multi mount mapent too long");
4d476f
 		return CHE_FAIL;
4d476f
@@ -793,10 +795,13 @@ update_offset_entry(struct autofs_point
4d476f
 		strcat(m_mapent, myoptions);
4d476f
 		if (loc) {
4d476f
 			strcat(m_mapent, " ");
4d476f
-			strcat(m_mapent, loc);
4d476f
+			if (loc)
4d476f
+				strcat(m_mapent, loc);
4d476f
 		}
4d476f
-	} else
4d476f
-		strcpy(m_mapent, loc);
4d476f
+	} else {
4d476f
+		if (loc)
4d476f
+			strcpy(m_mapent, loc);
4d476f
+	}
4d476f
 
4d476f
 	ret = cache_update_offset(mc, name, m_key, m_mapent, age);
4d476f
 	if (ret == CHE_DUPLICATE)
4d476f
@@ -923,9 +928,15 @@ static int parse_mapent(const char *ent,
4d476f
 	l = chunklen(p, check_colon(p));
4d476f
 	loc = dequote(p, l, logopt);
4d476f
 	if (!loc) {
4d476f
-		warn(logopt, MODPREFIX "possible missing location");
4d476f
-		free(myoptions);
4d476f
-		return 0;
4d476f
+		if (strstr(myoptions, "fstype=autofs") &&
4d476f
+		    strstr(myoptions, "hosts")) {
4d476f
+			warn(logopt, MODPREFIX "possible missing location");
4d476f
+			free(myoptions);
4d476f
+			return 0;
4d476f
+		}
4d476f
+		*options = myoptions;
4d476f
+		*location = NULL;
4d476f
+		return (p - ent);
4d476f
 	}
4d476f
 
4d476f
 	/* Location can't begin with a '/' */
4d476f
@@ -953,10 +964,15 @@ static int parse_mapent(const char *ent,
4d476f
 		l = chunklen(p, check_colon(p));
4d476f
 		ent_chunk = dequote(p, l, logopt);
4d476f
 		if (!ent_chunk) {
4d476f
-			warn(logopt, MODPREFIX "null location or out of memory");
4d476f
-			free(myoptions);
4d476f
-			free(loc);
4d476f
-			return 0;
4d476f
+			if (strstr(myoptions, "fstype=autofs") &&
4d476f
+			    strstr(myoptions, "hosts")) {
4d476f
+				warn(logopt, MODPREFIX
4d476f
+				     "null location or out of memory");
4d476f
+				free(myoptions);
4d476f
+				free(loc);
4d476f
+				return 0;
4d476f
+			}
4d476f
+			goto next;
4d476f
 		}
4d476f
 
4d476f
 		/* Location can't begin with a '/' */
4d476f
@@ -992,7 +1008,7 @@ static int parse_mapent(const char *ent,
4d476f
 		strcat(loc, ent_chunk);
4d476f
 
4d476f
 		free(ent_chunk);
4d476f
-
4d476f
+next:
4d476f
 		p += l;
4d476f
 		p = skipspace(p);
4d476f
 	}
4d476f
@@ -1093,7 +1109,9 @@ static int mount_subtree(struct autofs_p
4d476f
 				cache_delete_offset_list(me->mc, name);
4d476f
 				return 1;
4d476f
 			}
4d476f
-			ro_len = strlen(ro_loc);
4d476f
+			ro_len = 0;
4d476f
+			if (ro_loc)
4d476f
+				ro_len = strlen(ro_loc);
4d476f
 
4d476f
 			tmp = alloca(mnt_root_len + 2);
4d476f
 			strcpy(tmp, mnt_root);
4d476f
@@ -1104,7 +1122,8 @@ static int mount_subtree(struct autofs_p
4d476f
 			rv = sun_mount(ap, root, name, namelen, ro_loc, ro_len, myoptions, ctxt);
4d476f
 
4d476f
 			free(myoptions);
4d476f
-			free(ro_loc);
4d476f
+			if (ro_loc)
4d476f
+				free(ro_loc);
4d476f
 		}
4d476f
 
4d476f
 		if (ro && rv == 0) {
4d476f
@@ -1420,16 +1439,13 @@ int parse_mount(struct autofs_point *ap,
4d476f
 
4d476f
 			l = parse_mapent(p, options, &myoptions, &loc, ap->logopt);
4d476f
 			if (!l) {
4d476f
-				if (!(strstr(myoptions, "fstype=autofs") &&
4d476f
-				      strstr(myoptions, "hosts"))) {
4d476f
-					cache_delete_offset_list(mc, name);
4d476f
-					cache_multi_unlock(me);
4d476f
-					cache_unlock(mc);
4d476f
-					free(path);
4d476f
-					free(options);
4d476f
-					pthread_setcancelstate(cur_state, NULL);
4d476f
-					return 1;
4d476f
-				}
4d476f
+				cache_delete_offset_list(mc, name);
4d476f
+				cache_multi_unlock(me);
4d476f
+				cache_unlock(mc);
4d476f
+				free(path);
4d476f
+				free(options);
4d476f
+				pthread_setcancelstate(cur_state, NULL);
4d476f
+				return 1;
4d476f
 			}
4d476f
 
4d476f
 			p += l;
4d476f
@@ -1450,12 +1466,14 @@ int parse_mount(struct autofs_point *ap,
4d476f
 				free(path);
4d476f
 				free(options);
4d476f
 				free(myoptions);
4d476f
-				free(loc);
4d476f
+				if (loc)
4d476f
+					free(loc);
4d476f
 				pthread_setcancelstate(cur_state, NULL);
4d476f
 				return 1;
4d476f
 			}
4d476f
 
4d476f
-			free(loc);
4d476f
+			if (loc)
4d476f
+				free(loc);
4d476f
 			free(path);
4d476f
 			free(myoptions);
4d476f
 		} while (*p == '/' || (*p == '"' && *(p + 1) == '/'));