2b0cd7cceb
Rebased on top of Martin Wilck's queue of ACKed upstream commits * https://github.com/openSUSE/multipath-tools/tree/upstream-queue * All previous patches have been reordered, with the exception of 0011-libdmmp-Add-support-for-upcoming-json-c-0.14.0.patch which has been replaced with 0029-fix-boolean-value-with-json-c-0.14.patch Modify 0054-RH-add-mpathconf.patch * remove default enable_foreign and property blacklist_exceptions settings, and deal with the builtin default change from 0031-libmultipath-set-enable_foreign-to-NONE-by-default.patch. Fixes bz #1853668 Add 0048-Makefile.inc-trim-extra-information-from-systemd-ver.patch Add 0049-kpartx-fix-Wsign-compare-error.patch * The above two patches have been submitted upstream
96 lines
2.6 KiB
Diff
96 lines
2.6 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: Benjamin Marzinski <bmarzins@redhat.com>
|
|
Date: Tue, 9 Jun 2020 16:35:28 -0500
|
|
Subject: [PATCH] libmultipath: fix parser issue with comments in strings
|
|
|
|
If a quoted string starts with '#' or '!', the parser will stop
|
|
parsing the line, thinking that it's a comment. It should only
|
|
be checking for comments outside of quoted strings. Fixed this and
|
|
added unit tests to verify it.
|
|
|
|
Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com>
|
|
---
|
|
libmultipath/parser.c | 4 +++-
|
|
tests/parser.c | 42 ++++++++++++++++++++++++++++++++++++++++++
|
|
2 files changed, 45 insertions(+), 1 deletion(-)
|
|
|
|
diff --git a/libmultipath/parser.c b/libmultipath/parser.c
|
|
index d478b177..11a6168c 100644
|
|
--- a/libmultipath/parser.c
|
|
+++ b/libmultipath/parser.c
|
|
@@ -300,8 +300,10 @@ alloc_strvec(char *string)
|
|
(isspace((int) *cp) || !isascii((int) *cp)))
|
|
&& *cp != '\0')
|
|
cp++;
|
|
- if (*cp == '\0' || *cp == '!' || *cp == '#')
|
|
+ if (*cp == '\0' ||
|
|
+ (!in_string && (*cp == '!' || *cp == '#'))) {
|
|
return strvec;
|
|
+ }
|
|
}
|
|
out:
|
|
vector_free(strvec);
|
|
diff --git a/tests/parser.c b/tests/parser.c
|
|
index 29859dac..5772391e 100644
|
|
--- a/tests/parser.c
|
|
+++ b/tests/parser.c
|
|
@@ -440,6 +440,46 @@ static void test18(void **state)
|
|
free_strvec(v);
|
|
}
|
|
|
|
+static void test19(void **state)
|
|
+{
|
|
+#define QUOTED19 "!value"
|
|
+ vector v = alloc_strvec("key \"" QUOTED19 "\"");
|
|
+ char *val;
|
|
+
|
|
+ assert_int_equal(VECTOR_SIZE(v), 4);
|
|
+ assert_string_equal(VECTOR_SLOT(v, 0), "key");
|
|
+ assert_true(is_quote(VECTOR_SLOT(v, 1)));
|
|
+ assert_string_equal(VECTOR_SLOT(v, 2), QUOTED19);
|
|
+ assert_true(is_quote(VECTOR_SLOT(v, 3)));
|
|
+ assert_int_equal(validate_config_strvec(v, test_file), 0);
|
|
+
|
|
+ val = set_value(v);
|
|
+ assert_string_equal(val, QUOTED19);
|
|
+
|
|
+ free(val);
|
|
+ free_strvec(v);
|
|
+}
|
|
+
|
|
+static void test20(void **state)
|
|
+{
|
|
+#define QUOTED20 "#value"
|
|
+ vector v = alloc_strvec("key \"" QUOTED20 "\"");
|
|
+ char *val;
|
|
+
|
|
+ assert_int_equal(VECTOR_SIZE(v), 4);
|
|
+ assert_string_equal(VECTOR_SLOT(v, 0), "key");
|
|
+ assert_true(is_quote(VECTOR_SLOT(v, 1)));
|
|
+ assert_string_equal(VECTOR_SLOT(v, 2), QUOTED20);
|
|
+ assert_true(is_quote(VECTOR_SLOT(v, 3)));
|
|
+ assert_int_equal(validate_config_strvec(v, test_file), 0);
|
|
+
|
|
+ val = set_value(v);
|
|
+ assert_string_equal(val, QUOTED20);
|
|
+
|
|
+ free(val);
|
|
+ free_strvec(v);
|
|
+}
|
|
+
|
|
int test_config_parser(void)
|
|
{
|
|
const struct CMUnitTest tests[] = {
|
|
@@ -461,6 +501,8 @@ int test_config_parser(void)
|
|
cmocka_unit_test(test16),
|
|
cmocka_unit_test(test17),
|
|
cmocka_unit_test(test18),
|
|
+ cmocka_unit_test(test19),
|
|
+ cmocka_unit_test(test20),
|
|
};
|
|
return cmocka_run_group_tests(tests, setup, teardown);
|
|
}
|
|
--
|
|
2.17.2
|
|
|