Blame SOURCES/autofs-5.1.3-fix-amd-parser-double-quote-handling.patch

603f99
autofs-5.1.3 - fix amd parser double quote handling
603f99
603f99
From: Ian Kent <raven@themaw.net>
603f99
603f99
While the natuaral usage of amd maps doesn't use double quotes
603f99
it is allowed to use them to enclose option values.
603f99
603f99
The options mount, umount and unmount usually require them to
603f99
preserve spaces in the option value.
603f99
603f99
Signed-off-by: Ian Kent <raven@themaw.net>
603f99
---
603f99
 CHANGELOG           |    1 
603f99
 modules/amd_parse.y |  150 ++++++++++++++++++++++++++++++++++++++++++++--------
603f99
 modules/amd_tok.l   |    4 +
603f99
 3 files changed, 132 insertions(+), 23 deletions(-)
603f99
603f99
--- autofs-5.0.7.orig/CHANGELOG
603f99
+++ autofs-5.0.7/CHANGELOG
603f99
@@ -274,6 +274,7 @@
603f99
 - remove expand_selectors() on amd parser entry.
603f99
 - fix amd defaults map entry handling.
603f99
 - refactor amd_parse.c.
603f99
+- fix amd parser double quote handling.
603f99
 
603f99
 25/07/2012 autofs-5.0.7
603f99
 =======================
603f99
--- autofs-5.0.7.orig/modules/amd_parse.y
603f99
+++ autofs-5.0.7/modules/amd_parse.y
603f99
@@ -99,6 +99,7 @@ static int amd_fprintf(FILE *, char *, .
603f99
 %token CUT
603f99
 %token NOT_EQUAL
603f99
 %token COMMA
603f99
+%token QUOTE
603f99
 %token OPTION_ASSIGN
603f99
 %token LBRACKET
603f99
 %token RBRACKET
603f99
@@ -268,62 +269,114 @@ option_assignment: MAP_OPTION OPTION_ASS
603f99
 	}
603f99
 	| MAP_OPTION OPTION_ASSIGN FS_OPT_VALUE
603f99
 	{
603f99
-		if (!strcmp($1, "fs"))
603f99
-			entry.fs = amd_strdup($3);
603f99
-		else if (!strcmp($1, "sublink"))
603f99
-			entry.sublink = amd_strdup($3);
603f99
-		else if (!strcmp($1, "pref")) {
603f99
-			if (!strcmp($3, "null"))
603f99
-				entry.pref = amd_strdup("");
603f99
-			else
603f99
-				entry.pref = amd_strdup($3);
603f99
+		/* Quoted value for type, maptype or cache assign */
603f99
+		if (!strcmp($1, "type")) {
603f99
+			if (!match_map_option_fs_type($1, $3))
603f99
+				YYABORT;
603f99
+		} else if (!strcmp($1, "maptype")) {
603f99
+			if (!match_map_option_map_type($1, $3))
603f99
+				YYABORT;
603f99
+		} else if (!strcmp($1, "cache")) {
603f99
+			if (!match_map_option_cache_option($3))
603f99
+				YYABORT;
603f99
 		} else {
603f99
-			amd_notify($1);
603f99
-			YYABORT;
603f99
+			char *fs_opt_val;
603f99
+
603f99
+			fs_opt_val = amd_strdup($3);
603f99
+			if (!fs_opt_val) {
603f99
+				amd_notify($3);
603f99
+				YYABORT;
603f99
+			}
603f99
+
603f99
+			if (!strcmp($1, "fs"))
603f99
+				entry.fs = fs_opt_val;
603f99
+			else if (!strcmp($1, "sublink")) {
603f99
+				entry.sublink = fs_opt_val;
603f99
+			} else if (!strcmp($1, "pref")) {
603f99
+				if (strcmp(fs_opt_val, "null"))
603f99
+					entry.pref = fs_opt_val;
603f99
+				else {
603f99
+					entry.pref = amd_strdup("");
603f99
+					if (!entry.pref) {
603f99
+						amd_notify($3);
603f99
+						free(fs_opt_val);
603f99
+						YYABORT;
603f99
+					}
603f99
+					free(fs_opt_val);
603f99
+				}
603f99
+			} else {
603f99
+				amd_notify($1);
603f99
+				free(fs_opt_val);
603f99
+				YYABORT;
603f99
+			}
603f99
 		}
603f99
 	}
603f99
 	| MAP_OPTION OPTION_ASSIGN
603f99
 	{
603f99
-		if (!strcmp($1, "fs"))
603f99
+		if (!strcmp($1, "fs")) {
603f99
 			entry.fs = amd_strdup("");
603f99
-		else {
603f99
+			if (!entry.fs) {
603f99
+				amd_notify($1);
603f99
+				YYABORT;
603f99
+			}
603f99
+		} else {
603f99
 			amd_notify($1);
603f99
 			YYABORT;
603f99
 		}
603f99
 	}
603f99
 	| FS_OPTION OPTION_ASSIGN FS_OPT_VALUE
603f99
 	{
603f99
+		char *fs_opt_val;
603f99
+
603f99
+		fs_opt_val = amd_strdup($3);
603f99
+		if (!fs_opt_val) {
603f99
+			amd_notify($1);
603f99
+			YYABORT;
603f99
+		}
603f99
+
603f99
 		if (!strcmp($1, "rhost"))
603f99
-			entry.rhost = amd_strdup($3);
603f99
+			entry.rhost = fs_opt_val;
603f99
 		else if (!strcmp($1, "rfs"))
603f99
-			entry.rfs = amd_strdup($3);
603f99
+			entry.rfs = fs_opt_val;
603f99
 		else if (!strcmp($1, "dev"))
603f99
-			entry.dev = amd_strdup($3);
603f99
+			entry.dev = fs_opt_val;
603f99
 		else if (!strcmp($1, "mount") ||
603f99
 			 !strcmp($1, "unmount") ||
603f99
 			 !strcmp($1, "umount")) {
603f99
 			amd_info("file system type program is not "
603f99
 				 "yet implemented, option ignored");
603f99
+			free(fs_opt_val);
603f99
 			YYABORT;
603f99
 		} else if (!strcmp($1, "delay") ||
603f99
 			   !strcmp($1, "cachedir")) {
603f99
 			sprintf(msg_buf, "option %s is not used by autofs", $1);
603f99
 			amd_info(msg_buf);
603f99
+			free(fs_opt_val);
603f99
 		} else {
603f99
 			amd_notify($1);
603f99
+			free(fs_opt_val);
603f99
 			YYABORT;
603f99
 		}
603f99
 	}
603f99
 	| FS_OPTION OPTION_ASSIGN
603f99
 	{
603f99
+		char *empty;
603f99
+
603f99
+		empty = amd_strdup("");
603f99
+		if (!empty) {
603f99
+			amd_notify($1);
603f99
+			YYABORT;
603f99
+		}
603f99
+
603f99
 		if (!strcmp($1, "rhost"))
603f99
-			entry.rhost = amd_strdup("");
603f99
+			entry.rhost = empty;
603f99
 		else if (!strcmp($1, "rfs"))
603f99
-			entry.rfs = amd_strdup("");
603f99
+			entry.rfs = empty;
603f99
 		else if (!strcmp($1, "dev"))
603f99
-			entry.dev = amd_strdup("");
603f99
+			entry.dev = empty;
603f99
 		else {
603f99
 			amd_notify($1);
603f99
+			free(empty);
603f99
 			YYABORT;
603f99
 		}
603f99
 	}
603f99
@@ -335,6 +388,14 @@ option_assignment: MAP_OPTION OPTION_ASS
603f99
 		}
603f99
 		memset(opts, 0, sizeof(opts));
603f99
 	}
603f99
+	| MNT_OPTION OPTION_ASSIGN QUOTE options QUOTE
603f99
+	{
603f99
+		if (!match_mnt_option_options($1, $4)) {
603f99
+			amd_notify($1);
603f99
+			YYABORT;
603f99
+		}
603f99
+		memset(opts, 0, sizeof(opts));
603f99
+	}
603f99
 	| MNT_OPTION OPTION_ASSIGN
603f99
 	{
603f99
 		memset(opts, 0, sizeof(opts));
603f99
@@ -601,11 +662,56 @@ static int amd_fprintf(FILE *f, char *ms
603f99
 
603f99
 static char *amd_strdup(char *str)
603f99
 {
603f99
+	unsigned int quoted, len;
603f99
 	char *tmp;
603f99
 
603f99
-	tmp = strdup(str);
603f99
-	if (!tmp)
603f99
-		amd_error("memory allocation error");
603f99
+	len = strlen(str);
603f99
+	quoted = 0;
603f99
+
603f99
+	if (*str == '"') {
603f99
+		quoted = 1;
603f99
+		len -= 2;
603f99
+	}
603f99
+
603f99
+	tmp = strdup(str + quoted);
603f99
+	if (!tmp) {
603f99
+		amd_msg("memory allocation error");
603f99
+		return NULL;
603f99
+	} else {
603f99
+		unsigned int squote;
603f99
+		char *ptr;
603f99
+
603f99
+		if (quoted) {
603f99
+			if (tmp[len] != '"') {
603f99
+				sprintf(msg_buf,
603f99
+					"unmatched double quote near: %s", str);
603f99
+				amd_info(msg_buf);
603f99
+				free(tmp);
603f99
+				return NULL;
603f99
+			}
603f99
+			tmp[len] = 0;
603f99
+		}
603f99
+
603f99
+		/* Check for matching single quotes */
603f99
+		if (!strchr(tmp, 39))
603f99
+			goto done;
603f99
+
603f99
+		ptr = tmp;
603f99
+		squote = 0;
603f99
+		while (*ptr) {
603f99
+			if (*ptr == 39)
603f99
+				squote = !squote;
603f99
+			ptr++;
603f99
+		}
603f99
+		if (squote) {
603f99
+			sprintf(msg_buf,
603f99
+				"unmatched single quote near: %s", str);
603f99
+			amd_info(msg_buf);
603f99
+			free(tmp);
603f99
+			return NULL;
603f99
+		}
603f99
+	}
603f99
+done:
603f99
 	return tmp;
603f99
 }
603f99
 
603f99
--- autofs-5.0.7.orig/modules/amd_tok.l
603f99
+++ autofs-5.0.7/modules/amd_tok.l
603f99
@@ -94,7 +94,7 @@ IP6ADDR		((([A-Fa-f0-9]{1,4}\:\:?){1,7}[
603f99
 V6MASK		(12[0-8]|1[0-1][0-9]|[1-9][0-9]|[1-9])
603f99
 
603f99
 FOPT		(({QSTR}|{FSTR}|{MACRO})+)
603f99
-OPTS		({OSTR}(=({VSTR}|{QSTR}|{MACRO})+)?)
603f99
+OPTS		({OSTR}(=({VSTR}|{MACRO})+)?)
603f99
 SOPT		(({SSTR}|{QSTR}|{MACRO})+)
603f99
 NOPT		({SSTR}|(({IP4ADDR}(\/{V4MASK})?)|({IP6ADDR}(\/{V6MASK})?)))
603f99
 
603f99
@@ -288,6 +288,8 @@ CUTSEP		(\|\||\/)
603f99
 
603f99
 	,+ { return COMMA; }
603f99
 
603f99
+	"\"" { return QUOTE; }
603f99
+
603f99
 	{OPTS} {
603f99
 		amd_copy_buffer();
603f99
 		return OPTION;