netfilter-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Pablo M. Bermudo Garay" <pablombg@gmail.com>
To: netfilter-devel@vger.kernel.org
Cc: "Pablo M. Bermudo Garay" <pablombg@gmail.com>
Subject: [PATCH nft 3/3] tests: fix crash when rule test is malformed
Date: Tue,  1 Dec 2015 23:45:23 +0100	[thread overview]
Message-ID: <1449009923-10726-3-git-send-email-pablombg@gmail.com> (raw)
In-Reply-To: <1449009923-10726-1-git-send-email-pablombg@gmail.com>

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.

Signed-off-by: Pablo M. Bermudo Garay <pablombg@gmail.com>
---
 tests/regression/nft-test.py | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)

diff --git a/tests/regression/nft-test.py b/tests/regression/nft-test.py
index 9d623b7..e68087f 100755
--- a/tests/regression/nft-test.py
+++ b/tests/regression/nft-test.py
@@ -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()
-- 
2.6.2


  parent reply	other threads:[~2015-12-01 22:46 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-12-01 22:45 [PATCH nft 1/3] tests: add *.got files to .gitignore Pablo M. Bermudo Garay
2015-12-01 22:45 ` [PATCH nft 2/3] tests: remove useless logic Pablo M. Bermudo Garay
2015-12-01 22:45 ` Pablo M. Bermudo Garay [this message]
2015-12-10 17:28 ` [PATCH nft 1/3] tests: add *.got files to .gitignore Pablo Neira Ayuso
2015-12-14 19:39 ` Pablo Neira Ayuso

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1449009923-10726-3-git-send-email-pablombg@gmail.com \
    --to=pablombg@gmail.com \
    --cc=netfilter-devel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).