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

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