From: Dmitry V. Levin Date: Wed, 8 Mar 2023 08:00:00 +0000 (+0000) Subject: udev_rules_parse_file: issue diagnostics about line continuation at EOF X-Git-Tag: v254-rc1~1086^2 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F26698%2Fhead;p=thirdparty%2Fsystemd.git udev_rules_parse_file: issue diagnostics about line continuation at EOF When udev rules file ends with a line continuation, the parser used to silently ignore the line without any diagnostics at all. It's time to break the vow of silence and let the parser issue some error diagnostics. --- diff --git a/src/udev/udev-rules.c b/src/udev/udev-rules.c index 21223e01186..9d831a60047 100644 --- a/src/udev/udev-rules.c +++ b/src/udev/udev-rules.c @@ -1279,6 +1279,7 @@ int udev_rules_parse_file(UdevRules *rules, const char *filename) { line_nr++; line = skip_leading_chars(buf, NULL); + /* Lines beginning with '#' are ignored regardless of line continuation. */ if (line[0] == '#') continue; @@ -1320,6 +1321,10 @@ int udev_rules_parse_file(UdevRules *rules, const char *filename) { ignore_line = false; } + if (continuation) + log_line_error(rule_file, line_nr, + "Unexpected EOF after line continuation, line ignored"); + rule_resolve_goto(rule_file); return 0; } diff --git a/test/units/testsuite-17.11.sh b/test/units/testsuite-17.11.sh index d68aa69d41d..ed5da16c073 100755 --- a/test/units/testsuite-17.11.sh +++ b/test/units/testsuite-17.11.sh @@ -40,10 +40,18 @@ printf 'RUN+="/bin/true"%8175s\\\n' ' ' ' ' >sample.rules echo >>sample.rules udevadm verify sample.rules -printf 'RUN+="/bin/true"%8176s\\\n' ' ' ' ' >sample.rules +printf 'RUN+="/bin/true"%8176s\\\n #\n' ' ' ' ' >sample.rules echo >>sample.rules cat >exp <<'EOF' -sample.rules:3 Line is too long, ignored +sample.rules:5 Line is too long, ignored +sample.rules: udev rules check failed +EOF +(! udevadm verify sample.rules 2>err) +diff exp err + +printf '\\\n' >sample.rules +cat >exp <<'EOF' +sample.rules:1 Unexpected EOF after line continuation, line ignored sample.rules: udev rules check failed EOF (! udevadm verify sample.rules 2>err)