alloc_strvec() will never create a strvec with multiple tokens between
the quote tokens.  Verify this in validate_config_strvec(), and simplify
set_value() by only reading one value after a quote token.

Signed-off-by: Benjamin Marzinski <bmarz...@redhat.com>
---
 libmpathutil/parser.c | 64 ++++++++++++++-----------------------------
 1 file changed, 21 insertions(+), 43 deletions(-)

diff --git a/libmpathutil/parser.c b/libmpathutil/parser.c
index 8d3ac53a..ac4eb1fd 100644
--- a/libmpathutil/parser.c
+++ b/libmpathutil/parser.c
@@ -333,59 +333,33 @@ void *
 set_value(vector strvec)
 {
        char *str = VECTOR_SLOT(strvec, 1);
-       size_t size;
-       int i = 0;
-       int len = 0;
        char *alloc = NULL;
-       char *tmp;
 
        if (!str) {
                condlog(0, "option '%s' missing value",
                        (char *)VECTOR_SLOT(strvec, 0));
                return NULL;
        }
-       if (!is_quote(str)) {
-               size = strlen(str);
-               if (size == 0) {
-                       condlog(0, "option '%s' has empty value",
-                               (char *)VECTOR_SLOT(strvec, 0));
-                       return NULL;
-               }
-               alloc = calloc(1, sizeof (char) * (size + 1));
-               if (alloc)
-                       memcpy(alloc, str, size);
-               else
-                       goto oom;
-               return alloc;
-       }
-       /* Even empty quotes counts as a value (An empty string) */
-       alloc = (char *)calloc(1, sizeof (char));
-       if (!alloc)
-               goto oom;
-       for (i = 2; i < VECTOR_SIZE(strvec); i++) {
-               str = VECTOR_SLOT(strvec, i);
-               if (!str) {
-                       free(alloc);
-                       condlog(0, "parse error for option '%s'",
-                               (char *)VECTOR_SLOT(strvec, 0));
-                       return NULL;
+       if (is_quote(str)) {
+               if (VECTOR_SIZE(strvec) > 2) {
+                       str = VECTOR_SLOT(strvec, 2);
+                       if (!str) {
+                               condlog(0, "parse error for option '%s'",
+                                       (char *)VECTOR_SLOT(strvec, 0));
+                               return NULL;
+                       }
                }
-               if (is_quote(str))
-                       break;
-               tmp = alloc;
-               /* The first +1 is for the NULL byte. The rest are for the
-                * spaces between words */
-               len += strlen(str) + 1;
-               alloc = realloc(alloc, sizeof (char) * len);
-               if (!alloc) {
-                       free(tmp);
-                       goto oom;
+               /* Even empty quotes counts as a value (An empty string) */
+               if (is_quote(str)) {
+                       alloc = (char *)calloc(1, sizeof (char));
+                       if (!alloc)
+                               goto oom;
+                       return alloc;
                }
-               if (*alloc != '\0')
-                       strncat(alloc, " ", len - strlen(alloc));
-               strncat(alloc, str, len - strlen(alloc) - 1);
        }
-       return alloc;
+       alloc = strdup(str);
+       if (alloc)
+               return alloc;
 oom:
        condlog(0, "can't allocate memory for option '%s'",
                (char *)VECTOR_SLOT(strvec, 0));
@@ -496,6 +470,10 @@ validate_config_strvec(vector strvec, const char *file)
                        if (VECTOR_SIZE(strvec) > i + 1)
                                condlog(0, "ignoring extra data starting with 
'%s' on line %d of %s", (char *)VECTOR_SLOT(strvec, (i + 1)), line_nr, file);
                        return 0;
+               } else if (i > 3) {
+                       /* There should only ever be one token between quotes */
+                       condlog(0, "parsing error starting with '%s' on line %d 
of %s", str, line_nr, file);
+                       return -1;
                }
        }
        condlog(0, "missing closing quotes on line %d of %s",
-- 
2.17.2

--
dm-devel mailing list
dm-devel@redhat.com
https://listman.redhat.com/mailman/listinfo/dm-devel

Reply via email to