Skip to content

Commit 9adbfeb

Browse files
committed
conf-parser: ignore trailing back-slash in comment
Fixes systemd#10598.
1 parent 8d2411f commit 9adbfeb

File tree

2 files changed

+21
-6
lines changed

2 files changed

+21
-6
lines changed

src/shared/conf-parser.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ static int parse_line(
174174
if (!*l)
175175
return 0;
176176

177-
if (strchr(COMMENTS "\n", *l))
177+
if (*l == '\n')
178178
return 0;
179179

180180
include = first_word(l, ".include");
@@ -327,6 +327,9 @@ int config_parse(const char *unit,
327327
return r;
328328
}
329329

330+
if (strchr(COMMENTS, *buf))
331+
continue;
332+
330333
l = buf;
331334
if (!(flags & CONFIG_PARSE_REFUSE_BOM)) {
332335
char *q;

src/test/test-conf-parser.c

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,18 @@ static const char* const config_file[] = {
274274
"2\\\n"
275275
"3\n",
276276

277+
"[Section]\n"
278+
"#hogehoge\\\n" /* continuation is ignored in comment */
279+
"setting1=1\\\n" /* normal continuation */
280+
"2\\\n"
281+
"3\n",
282+
283+
"[Section]\n"
284+
"setting1=1\\\n" /* normal continuation */
285+
"#hogehoge\\\n" /* commented out line in continuation is ignored */
286+
"2\\\n"
287+
"3\n",
288+
277289
"[Section]\n"
278290
"setting1=1\\\n" /* continuation with extra trailing backslash at the end */
279291
"2\\\n"
@@ -350,27 +362,27 @@ static void test_config_parse(unsigned i, const char *s) {
350362
assert_se(streq(setting1, "1"));
351363
break;
352364

353-
case 4 ... 5:
365+
case 4 ... 7:
354366
assert_se(r == 0);
355367
assert_se(streq(setting1, "1 2 3"));
356368
break;
357369

358-
case 6:
370+
case 8:
359371
assert_se(r == 0);
360372
assert_se(streq(setting1, "1\\\\ \\\\2"));
361373
break;
362374

363-
case 7:
375+
case 9:
364376
assert_se(r == 0);
365377
assert_se(streq(setting1, x1000("ABCD")));
366378
break;
367379

368-
case 8 ... 9:
380+
case 10 ... 11:
369381
assert_se(r == 0);
370382
assert_se(streq(setting1, x1000("ABCD") " foobar"));
371383
break;
372384

373-
case 10 ... 11:
385+
case 12 ... 13:
374386
assert_se(r == -ENOBUFS);
375387
assert_se(setting1 == NULL);
376388
break;

0 commit comments

Comments
 (0)