]> git.ipfire.org Git - people/pmueller/ipfire-3.x.git/blame - multipath-tools/patches/0087-RHBZ-1110013-config-error-checking.patch
multipath-tools: Update to snapshot from 2013-02-22
[people/pmueller/ipfire-3.x.git] / multipath-tools / patches / 0087-RHBZ-1110013-config-error-checking.patch
CommitLineData
289c5516
MT
1---
2 libmultipath/parser.c | 154 ++++++++++++++++++++++++++++++++++++++++----------
3 1 file changed, 126 insertions(+), 28 deletions(-)
4
5Index: 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)
10 char *alloc = NULL;
11 char *tmp;
12
13- if (!str)
14+ if (!str) {
15+ condlog(0, "option '%s' missing value",
16+ (char *)VECTOR_SLOT(strvec, 0));
17 return NULL;
18-
19+ }
20 size = strlen(str);
21- if (size == 0)
22+ if (size == 0) {
23+ condlog(0, "option '%s' has empty value",
24+ (char *)VECTOR_SLOT(strvec, 0));
25 return NULL;
26-
27- if (*str == '"') {
28- for (i = 2; i < VECTOR_SIZE(strvec); i++) {
29- str = VECTOR_SLOT(strvec, i);
30- len += strlen(str);
31- if (!alloc)
32- alloc =
33- (char *) MALLOC(sizeof (char *) *
34- (len + 1));
35- else {
36- alloc =
37- REALLOC(alloc, sizeof (char *) * (len + 1));
38- tmp = VECTOR_SLOT(strvec, i-1);
39- if (alloc && *str != '"' && *tmp != '"')
40- strncat(alloc, " ", 1);
41- }
42-
43- if (alloc && i != VECTOR_SIZE(strvec)-1)
44- strncat(alloc, str, strlen(str));
45- }
46- } else {
47- alloc = MALLOC(sizeof (char *) * (size + 1));
48+ }
49+ if (*str != '"') {
50+ alloc = MALLOC(sizeof (char) * (size + 1));
51 if (alloc)
52 memcpy(alloc, str, size);
53+ else
54+ condlog(0, "can't allocate memeory for option '%s'",
55+ (char *)VECTOR_SLOT(strvec, 0));
56+ return alloc;
57+ }
58+ /* Even empty quotes counts as a value (An empty string) */
59+ alloc = (char *) MALLOC(sizeof (char));
60+ if (!alloc) {
61+ condlog(0, "can't allocate memeory for option '%s'",
62+ (char *)VECTOR_SLOT(strvec, 0));
63+ return NULL;
64+ }
65+ for (i = 2; i < VECTOR_SIZE(strvec); i++) {
66+ str = VECTOR_SLOT(strvec, i);
67+ if (!str) {
68+ free(alloc);
69+ condlog(0, "parse error for option '%s'",
70+ (char *)VECTOR_SLOT(strvec, 0));
71+ return NULL;
72+ }
73+ if (*str == '"')
74+ break;
75+ tmp = alloc;
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);
80+ if (!alloc) {
81+ FREE(tmp);
82+ condlog(0, "can't allocate memeory for option '%s'",
83+ (char *)VECTOR_SLOT(strvec, 0));
84+ return NULL;
85+ }
86+ if (*alloc != '\0')
87+ strncat(alloc, " ", 1);
88+ strncat(alloc, str, strlen(str));
89 }
90 return alloc;
91 }
92@@ -465,6 +486,74 @@ void free_uniques(vector uniques)
93 }
94
95 int
96+is_sublevel_keyword(char *str)
97+{
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);
103+}
104+
105+int
106+validate_config_strvec(vector strvec)
107+{
108+ char *str;
109+ int i;
110+
111+ str = VECTOR_SLOT(strvec, 0);
112+ if (str == NULL) {
113+ condlog(0, "can't parse option on line %d of config file",
114+ line_nr);
115+ return -1;
116+ }
117+ if (*str == '}') {
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);
120+ return 0;
121+ }
122+ if (*str == '{') {
123+ condlog(0, "invalid keyword '%s' on line %d of config file", str, line_nr);
124+ return -1;
125+ }
126+ if (is_sublevel_keyword(str)) {
127+ str = VECTOR_SLOT(strvec, 1);
128+ if (str == NULL)
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);
134+ return 0;
135+ }
136+ str = VECTOR_SLOT(strvec, 1);
137+ if (str == NULL) {
138+ condlog(0, "missing value for option '%s' on line %d of config file", (char *)VECTOR_SLOT(strvec, 0), line_nr);
139+ return -1;
140+ }
141+ if (*str != '"') {
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);
144+ return 0;
145+ }
146+ for (i = 2; i < VECTOR_SIZE(strvec); i++) {
147+ str = VECTOR_SLOT(strvec, i);
148+ if (str == NULL) {
149+ condlog(0, "can't parse value on line %d of config file", line_nr);
150+ return -1;
151+ }
152+ if (*str == '"') {
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);
155+ return 0;
156+ }
157+ }
158+ condlog(0, "missing closing quotes on line %d of config file",
159+ line_nr);
160+ return 0;
161+}
162+
163+int
164 process_stream(vector keywords)
165 {
166 int i;
167@@ -494,11 +583,20 @@ process_stream(vector keywords)
168 if (!strvec)
169 continue;
170
171+ if (validate_config_strvec(strvec) != 0) {
172+ free_strvec(strvec);
173+ continue;
174+ }
175+
176 str = VECTOR_SLOT(strvec, 0);
177
178- if (!strcmp(str, EOB) && kw_level > 0) {
179- free_strvec(strvec);
180- break;
181+ if (!strcmp(str, EOB)) {
182+ if (kw_level > 0) {
183+ free_strvec(strvec);
184+ break;
185+ }
186+ condlog(0, "unmatched '%s' at line %d of config file",
187+ EOB, line_nr);
188 }
189
190 for (i = 0; i < VECTOR_SIZE(keywords); i++) {