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

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