|
|
49190a |
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
|
49190a |
From: Benjamin Marzinski <bmarzins@redhat.com>
|
|
|
49190a |
Date: Mon, 8 Jun 2020 20:23:56 -0500
|
|
|
49190a |
Subject: [PATCH] libmultipath: fix parser issue with comments in strings
|
|
|
49190a |
|
|
|
49190a |
If a quoted string starts with '#' or '!', the parser will stop
|
|
|
49190a |
parsing the line, thinking that it's a comment. It should only
|
|
|
49190a |
be checking for comments outside of quoted strings. Fixed this and
|
|
|
49190a |
added unit tests to verify it.
|
|
|
49190a |
|
|
|
49190a |
Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com>
|
|
|
49190a |
---
|
|
|
49190a |
libmultipath/parser.c | 4 +++-
|
|
|
49190a |
tests/parser.c | 42 ++++++++++++++++++++++++++++++++++++++++++
|
|
|
49190a |
2 files changed, 45 insertions(+), 1 deletion(-)
|
|
|
49190a |
|
|
|
49190a |
diff --git a/libmultipath/parser.c b/libmultipath/parser.c
|
|
|
49190a |
index a184511b..a7285a35 100644
|
|
|
49190a |
--- a/libmultipath/parser.c
|
|
|
49190a |
+++ b/libmultipath/parser.c
|
|
|
49190a |
@@ -300,8 +300,10 @@ alloc_strvec(char *string)
|
|
|
49190a |
(isspace((int) *cp) || !isascii((int) *cp)))
|
|
|
49190a |
&& *cp != '\0')
|
|
|
49190a |
cp++;
|
|
|
49190a |
- if (*cp == '\0' || *cp == '!' || *cp == '#')
|
|
|
49190a |
+ if (*cp == '\0' ||
|
|
|
49190a |
+ (!in_string && (*cp == '!' || *cp == '#'))) {
|
|
|
49190a |
return strvec;
|
|
|
49190a |
+ }
|
|
|
49190a |
}
|
|
|
49190a |
out:
|
|
|
49190a |
vector_free(strvec);
|
|
|
49190a |
diff --git a/tests/parser.c b/tests/parser.c
|
|
|
49190a |
index 29859dac..5772391e 100644
|
|
|
49190a |
--- a/tests/parser.c
|
|
|
49190a |
+++ b/tests/parser.c
|
|
|
49190a |
@@ -440,6 +440,46 @@ static void test18(void **state)
|
|
|
49190a |
free_strvec(v);
|
|
|
49190a |
}
|
|
|
49190a |
|
|
|
49190a |
+static void test19(void **state)
|
|
|
49190a |
+{
|
|
|
49190a |
+#define QUOTED19 "!value"
|
|
|
49190a |
+ vector v = alloc_strvec("key \"" QUOTED19 "\"");
|
|
|
49190a |
+ char *val;
|
|
|
49190a |
+
|
|
|
49190a |
+ assert_int_equal(VECTOR_SIZE(v), 4);
|
|
|
49190a |
+ assert_string_equal(VECTOR_SLOT(v, 0), "key");
|
|
|
49190a |
+ assert_true(is_quote(VECTOR_SLOT(v, 1)));
|
|
|
49190a |
+ assert_string_equal(VECTOR_SLOT(v, 2), QUOTED19);
|
|
|
49190a |
+ assert_true(is_quote(VECTOR_SLOT(v, 3)));
|
|
|
49190a |
+ assert_int_equal(validate_config_strvec(v, test_file), 0);
|
|
|
49190a |
+
|
|
|
49190a |
+ val = set_value(v);
|
|
|
49190a |
+ assert_string_equal(val, QUOTED19);
|
|
|
49190a |
+
|
|
|
49190a |
+ free(val);
|
|
|
49190a |
+ free_strvec(v);
|
|
|
49190a |
+}
|
|
|
49190a |
+
|
|
|
49190a |
+static void test20(void **state)
|
|
|
49190a |
+{
|
|
|
49190a |
+#define QUOTED20 "#value"
|
|
|
49190a |
+ vector v = alloc_strvec("key \"" QUOTED20 "\"");
|
|
|
49190a |
+ char *val;
|
|
|
49190a |
+
|
|
|
49190a |
+ assert_int_equal(VECTOR_SIZE(v), 4);
|
|
|
49190a |
+ assert_string_equal(VECTOR_SLOT(v, 0), "key");
|
|
|
49190a |
+ assert_true(is_quote(VECTOR_SLOT(v, 1)));
|
|
|
49190a |
+ assert_string_equal(VECTOR_SLOT(v, 2), QUOTED20);
|
|
|
49190a |
+ assert_true(is_quote(VECTOR_SLOT(v, 3)));
|
|
|
49190a |
+ assert_int_equal(validate_config_strvec(v, test_file), 0);
|
|
|
49190a |
+
|
|
|
49190a |
+ val = set_value(v);
|
|
|
49190a |
+ assert_string_equal(val, QUOTED20);
|
|
|
49190a |
+
|
|
|
49190a |
+ free(val);
|
|
|
49190a |
+ free_strvec(v);
|
|
|
49190a |
+}
|
|
|
49190a |
+
|
|
|
49190a |
int test_config_parser(void)
|
|
|
49190a |
{
|
|
|
49190a |
const struct CMUnitTest tests[] = {
|
|
|
49190a |
@@ -461,6 +501,8 @@ int test_config_parser(void)
|
|
|
49190a |
cmocka_unit_test(test16),
|
|
|
49190a |
cmocka_unit_test(test17),
|
|
|
49190a |
cmocka_unit_test(test18),
|
|
|
49190a |
+ cmocka_unit_test(test19),
|
|
|
49190a |
+ cmocka_unit_test(test20),
|
|
|
49190a |
};
|
|
|
49190a |
return cmocka_run_group_tests(tests, setup, teardown);
|
|
|
49190a |
}
|
|
|
49190a |
--
|
|
|
49190a |
2.17.2
|
|
|
49190a |
|