2 libmultipath/parser.c | 154 ++++++++++++++++++++++++++++++++++++++++----------
3 1 file changed, 126 insertions(+), 28 deletions(-)
5 Index: multipath-tools-130222/libmultipath/parser.c
6 ===================================================================
7 --- multipath-tools-130222.orig/libmultipath/parser.c
8 +++ multipath-tools-130222/libmultipath/parser.c
9 @@ -395,36 +395,57 @@ set_value(vector strvec)
15 + condlog(0, "option '%s' missing value",
16 + (char *)VECTOR_SLOT(strvec, 0));
23 + condlog(0, "option '%s' has empty value",
24 + (char *)VECTOR_SLOT(strvec, 0));
28 - for (i = 2; i < VECTOR_SIZE(strvec); i++) {
29 - str = VECTOR_SLOT(strvec, i);
33 - (char *) MALLOC(sizeof (char *) *
37 - REALLOC(alloc, sizeof (char *) * (len + 1));
38 - tmp = VECTOR_SLOT(strvec, i-1);
39 - if (alloc && *str != '"' && *tmp != '"')
40 - strncat(alloc, " ", 1);
43 - if (alloc && i != VECTOR_SIZE(strvec)-1)
44 - strncat(alloc, str, strlen(str));
47 - alloc = MALLOC(sizeof (char *) * (size + 1));
50 + alloc = MALLOC(sizeof (char) * (size + 1));
52 memcpy(alloc, str, size);
54 + condlog(0, "can't allocate memeory for option '%s'",
55 + (char *)VECTOR_SLOT(strvec, 0));
58 + /* Even empty quotes counts as a value (An empty string) */
59 + alloc = (char *) MALLOC(sizeof (char));
61 + condlog(0, "can't allocate memeory for option '%s'",
62 + (char *)VECTOR_SLOT(strvec, 0));
65 + for (i = 2; i < VECTOR_SIZE(strvec); i++) {
66 + str = VECTOR_SLOT(strvec, i);
69 + condlog(0, "parse error for option '%s'",
70 + (char *)VECTOR_SLOT(strvec, 0));
76 + /* The first +1 is for the NULL byte. The rest are for the
77 + * spaces between words */
78 + len += strlen(str) + 1;
79 + alloc = REALLOC(alloc, sizeof (char) * len);
82 + condlog(0, "can't allocate memeory for option '%s'",
83 + (char *)VECTOR_SLOT(strvec, 0));
87 + strncat(alloc, " ", 1);
88 + strncat(alloc, str, strlen(str));
92 @@ -465,6 +486,74 @@ void free_uniques(vector uniques)
96 +is_sublevel_keyword(char *str)
98 + return (strcmp(str, "defaults") == 0 || strcmp(str, "blacklist") == 0 ||
99 + strcmp(str, "blacklist_exceptions") == 0 ||
100 + strcmp(str, "devices") == 0 || strcmp(str, "devices") == 0 ||
101 + strcmp(str, "device") == 0 || strcmp(str, "multipaths") == 0 ||
102 + strcmp(str, "multipath") == 0);
106 +validate_config_strvec(vector strvec)
111 + str = VECTOR_SLOT(strvec, 0);
113 + condlog(0, "can't parse option on line %d of config file",
118 + if (VECTOR_SIZE(strvec) > 1)
119 + condlog(0, "ignoring extra data starting with '%s' on line %d of config file", (char *)VECTOR_SLOT(strvec, 1), line_nr);
123 + condlog(0, "invalid keyword '%s' on line %d of config file", str, line_nr);
126 + if (is_sublevel_keyword(str)) {
127 + str = VECTOR_SLOT(strvec, 1);
129 + condlog(0, "missing '{' on line %d of config file", line_nr);
130 + else if (*str != '{')
131 + condlog(0, "expecting '{' on line %d of config file. found '%s'", line_nr, str);
132 + else if (VECTOR_SIZE(strvec) > 2)
133 + condlog(0, "ignoring extra data starting with '%s' on line %d of config file", (char *)VECTOR_SLOT(strvec, 2), line_nr);
136 + str = VECTOR_SLOT(strvec, 1);
138 + condlog(0, "missing value for option '%s' on line %d of config file", (char *)VECTOR_SLOT(strvec, 0), line_nr);
142 + if (VECTOR_SIZE(strvec) > 2)
143 + condlog(0, "ignoring extra data starting with '%s' on line %d of config file", (char *)VECTOR_SLOT(strvec, 2), line_nr);
146 + for (i = 2; i < VECTOR_SIZE(strvec); i++) {
147 + str = VECTOR_SLOT(strvec, i);
149 + condlog(0, "can't parse value on line %d of config file", line_nr);
153 + if (VECTOR_SIZE(strvec) > i + 1)
154 + condlog(0, "ignoring extra data starting with '%s' on line %d of config file", (char *)VECTOR_SLOT(strvec, (i + 1)), line_nr);
158 + condlog(0, "missing closing quotes on line %d of config file",
164 process_stream(vector keywords)
167 @@ -494,11 +583,20 @@ process_stream(vector keywords)
171 + if (validate_config_strvec(strvec) != 0) {
172 + free_strvec(strvec);
176 str = VECTOR_SLOT(strvec, 0);
178 - if (!strcmp(str, EOB) && kw_level > 0) {
179 - free_strvec(strvec);
181 + if (!strcmp(str, EOB)) {
182 + if (kw_level > 0) {
183 + free_strvec(strvec);
186 + condlog(0, "unmatched '%s' at line %d of config file",
190 for (i = 0; i < VECTOR_SIZE(keywords); i++) {