]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
rule-syntax-check: fix handling of runaway strings in comma splitting (#8298)
authorFilipe Brandenburger <filbranden@google.com>
Wed, 28 Feb 2018 00:11:38 +0000 (16:11 -0800)
committerEvgeny Vereshchagin <evvers@ya.ru>
Wed, 28 Feb 2018 00:11:38 +0000 (03:11 +0300)
A runaway string should still be returned by the code that splits on
commas, so add a '?' to the regex so that the last '"?' in a string
still produces a valid block for the split code.

Tested:

  ACTION=="remove\"GOTO=""

Which then produced:

  $ test/rule-syntax-check.py src/login/70-uaccess.rules
  # looking at src/login/70-uaccess.rules
  Invalid line src/login/70-uaccess.rules:10: ACTION=="remove\"GOTO=""
    clause: ACTION=="remove\"GOTO=""

test/rule-syntax-check.py

index 7ee34eb7002c800539e749382f89e2cb3f2b633e..a245432b62c023f4346e843465397e77d5ec485f 100755 (executable)
@@ -34,7 +34,9 @@ args_tests = re.compile(r'(ATTRS?|ENV|TEST){([a-zA-Z0-9/_.*%-]+)}\s*(?:=|!)=\s*'
 no_args_assign = re.compile(r'(NAME|SYMLINK|OWNER|GROUP|MODE|TAG|RUN|LABEL|GOTO|OPTIONS|IMPORT)\s*(?:\+=|:=|=)\s*' + quoted_string_re + '$')
 args_assign = re.compile(r'(ATTR|ENV|IMPORT|RUN){([a-zA-Z0-9/_.*%-]+)}\s*(=|\+=)\s*' + quoted_string_re + '$')
 # Find comma-separated groups, but allow commas that are inside quoted strings.
-comma_separated_group_re = re.compile(r'(?:[^,"]|' + quoted_string_re + ')+')
+# Using quoted_string_re + '?' so that strings missing the last double quote
+# will still match for this part that splits on commas.
+comma_separated_group_re = re.compile(r'(?:[^,"]|' + quoted_string_re + '?)+')
 
 result = 0
 buffer = ''