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

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