]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
conf-parser: ignore trailing back-slash in comment
authorYu Watanabe <watanabe.yu+github@gmail.com>
Tue, 6 Nov 2018 04:22:09 +0000 (13:22 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Thu, 8 Nov 2018 09:09:04 +0000 (18:09 +0900)
Fixes #10598.

src/shared/conf-parser.c
src/test/test-conf-parser.c

index b9c5b412f237fd70b2631e297657a40e9ff8e1b2..493ece9d09eff0118078db71f5c4c487a6b30050 100644 (file)
@@ -174,7 +174,7 @@ static int parse_line(
         if (!*l)
                 return 0;
 
-        if (strchr(COMMENTS "\n", *l))
+        if (*l == '\n')
                 return 0;
 
         include = first_word(l, ".include");
@@ -327,6 +327,9 @@ int config_parse(const char *unit,
                         return r;
                 }
 
+                if (strchr(COMMENTS, *buf))
+                        continue;
+
                 l = buf;
                 if (!(flags & CONFIG_PARSE_REFUSE_BOM)) {
                         char *q;
index 91f1d9a386712b3ba877e7e8182e65d362bd2d70..368e02cb338a6a1277db64eb06df8b9c52a7ffb4 100644 (file)
@@ -274,6 +274,18 @@ static const char* const config_file[] = {
         "2\\\n"
         "3\n",
 
+        "[Section]\n"
+        "#hogehoge\\\n"      /* continuation is ignored in comment */
+        "setting1=1\\\n"     /* normal continuation */
+        "2\\\n"
+        "3\n",
+
+        "[Section]\n"
+        "setting1=1\\\n"     /* normal continuation */
+        "#hogehoge\\\n"      /* commented out line in continuation is ignored */
+        "2\\\n"
+        "3\n",
+
         "[Section]\n"
         "setting1=1\\\n"     /* continuation with extra trailing backslash at the end */
         "2\\\n"
@@ -350,27 +362,27 @@ static void test_config_parse(unsigned i, const char *s) {
                 assert_se(streq(setting1, "1"));
                 break;
 
-        case 4 ... 5:
+        case 4 ... 7:
                 assert_se(r == 0);
                 assert_se(streq(setting1, "1 2 3"));
                 break;
 
-        case 6:
+        case 8:
                 assert_se(r == 0);
                 assert_se(streq(setting1, "1\\\\ \\\\2"));
                 break;
 
-        case 7:
+        case 9:
                 assert_se(r == 0);
                 assert_se(streq(setting1, x1000("ABCD")));
                 break;
 
-        case 8 ... 9:
+        case 10 ... 11:
                 assert_se(r == 0);
                 assert_se(streq(setting1, x1000("ABCD") " foobar"));
                 break;
 
-        case 10 ... 11:
+        case 12 ... 13:
                 assert_se(r == -ENOBUFS);
                 assert_se(setting1 == NULL);
                 break;