Blame SOURCES/0022-libmultipath-fix-parser-issue-with-comments-in-strin.patch

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