]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
conf-parser: accept trailing backslash at the end of the file (#8941)
authorFilipe Brandenburger <filbranden@google.com>
Thu, 10 May 2018 01:10:07 +0000 (18:10 -0700)
committerLennart Poettering <lennart@poettering.net>
Thu, 10 May 2018 01:10:07 +0000 (18:10 -0700)
This makes it behave the same whether there is a blank line or not at
the end of the file.  This is also consistent with the behavior of the
shell on a shell script that ends on a trailing backslash at the last
line.

Added tests to test_config_parse(), which only pass if the corresponding
change to config_parse() is included.

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

index fec7c62802234427bd6a0ea7879e61516f61b650..9b822dd49a926edd87b7dd56a8134d0ce9c20b99 100644 (file)
@@ -401,6 +401,27 @@ int config_parse(const char *unit,
                 continuation = mfree(continuation);
         }
 
+        if (continuation) {
+                r = parse_line(unit,
+                               filename,
+                               ++line,
+                               sections,
+                               lookup,
+                               table,
+                               flags,
+                               &section,
+                               &section_line,
+                               &section_ignored,
+                               continuation,
+                               userdata);
+                if (r < 0) {
+                        if (flags & CONFIG_PARSE_WARN)
+                                log_warning_errno(r, "%s:%u: Failed to parse file: %m", filename, line);
+                        return r;
+
+                }
+        }
+
         return 0;
 }
 
index db62440e9b17db7120cad58b3557f649278fd2c3..90ec20378f6f313b4852e48ab63f52ea1da50bd0 100644 (file)
@@ -277,6 +277,11 @@ static const char* const config_file[] = {
         "2\\\n"
         "3\n",
 
+        "[Section]\n"
+        "setting1=1\\\n"     /* continuation with extra trailing backslash at the end */
+        "2\\\n"
+        "3\\\n",
+
         "[Section]\n"
         "setting1=1\\\\\\\n" /* continuation with trailing escape symbols */
         "\\\\2\n",           /* note that C requires one level of escaping, so the
@@ -293,6 +298,11 @@ static const char* const config_file[] = {
         x1000("ABCD") "\\\n"
         "foobar",
 
+        "[Section]\n"
+        "setting1="          /* a line above LINE_MAX length, with continuation */
+        x1000("ABCD") "\\\n" /* and an extra trailing backslash */
+        "foobar\\\n",
+
         "[Section]\n"
         "setting1="          /* a line above the allowed limit: 9 + 1050000 + 1 */
         x1000(x1000("x") x10("abcde")) "\n",
@@ -346,27 +356,27 @@ static void test_config_parse(unsigned i, const char *s) {
                 assert_se(streq(setting1, "1"));
                 break;
 
-        case 4:
+        case 4 ... 5:
                 assert_se(r == 0);
                 assert_se(streq(setting1, "1 2 3"));
                 break;
 
-        case 5:
+        case 6:
                 assert_se(r == 0);
                 assert_se(streq(setting1, "1\\\\ \\\\2"));
                 break;
 
-        case 6:
+        case 7:
                 assert_se(r == 0);
                 assert_se(streq(setting1, x1000("ABCD")));
                 break;
 
-        case 7:
+        case 8 ... 9:
                 assert_se(r == 0);
                 assert_se(streq(setting1, x1000("ABCD") " foobar"));
                 break;
 
-        case 8 ... 9:
+        case 10 ... 11:
                 assert_se(r == -ENOBUFS);
                 assert_se(setting1 == NULL);
                 break;