]> git.ipfire.org Git - thirdparty/nftables.git/commitdiff
tests: fix crash when rule test is malformed
authorPablo M. Bermudo Garay <pablombg@gmail.com>
Tue, 1 Dec 2015 22:45:23 +0000 (23:45 +0100)
committerPablo Neira Ayuso <pablo@netfilter.org>
Mon, 14 Dec 2015 19:32:41 +0000 (20:32 +0100)
The tests script suffers a crash when a rule test line is malformed
(e.g. if expected result is missing). This commit fixes these crashes
and now the line is skipped and a warning is printed.

While at it, fix a malformed test line too.

Signed-off-by: Pablo M. Bermudo Garay <pablombg@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
tests/regression/any/meta.t
tests/regression/nft-test.py

index 6d9f9d22054595274bb06f2ab6a5b342a47da2cf..c03e7f4e47a91b6d69c2daae9509ac44e2ad86ff 100644 (file)
@@ -166,7 +166,7 @@ meta iifgroup 0;ok;iifgroup default
 meta iifgroup != 0;ok;iifgroup != default
 meta iifgroup default;ok;iifgroup default
 meta iifgroup != default;ok;iifgroup != default
-meta iifgroup {default};ok;;iifgroup {default}
+meta iifgroup {default};ok;iifgroup {default}
 - meta iifgroup != {default};ok
 meta iifgroup { 11,33};ok
 meta iifgroup {11-33};ok
index 9d623b70642ec4e7d35d5adea3a8e09ade3c351a..e68087f31dc975d87824f913bb10cfcee575860c 100755 (executable)
@@ -508,12 +508,6 @@ def rule_add(rule, table_list, chain_list, filename, lineno,
                     print_error("did not find payload information for rule '%s'" % rule[0], payload_log.name, 1)
 
         for chain in chain_list:
-            if len(rule) == 1:
-                reason = "Skipping malformed test. (" + \
-                    str(rule[0].rstrip('\n')) + ")"
-                print_warning(reason, filename, lineno)
-                continue
-
             unit_tests += 1
             table_flush(table, filename, lineno)
             table_info = " " + table[0] + " " + table[1] + " "
@@ -808,6 +802,11 @@ def run_test_file(filename, force_all_family_option, specific_file):
 
         # Rule
         rule = line.split(';')  # rule[1] Ok or FAIL
+        if len(rule) == 1 or len(rule) > 3 or rule[1].rstrip() not in {"ok", "fail"}:
+            reason = "Skipping malformed rule test. (" + line.rstrip('\n') + ")"
+            print_warning(reason, filename, lineno)
+            continue
+
         if line[0] == "-":  # Run omitted lines
             if need_fix_option:
                 rule[0] = rule[0].rstrip()[1:].strip()