From b0b12021d36debee40144b2c0b8a47bd7e9b0450 Mon Sep 17 00:00:00 2001 From: Shivani Bhardwaj Date: Wed, 13 Feb 2019 16:32:06 +0530 Subject: [PATCH] suricatasc: Fix command failures This commit addresses the following three cases: 1. Do not use maxsplit keyword arg maxsplit argument to the split command was not a part of Python 2 and using it with Python 2 causes the following failure: ``` TypeError: split() takes no keyword arguments ``` Avoid this by eliminating all the named arguments from split. 2. Fix failure on extra arguments Up until now, suricatasc fails if any command which is not supposed to take args is given args. Fix this by ignoring any extra params. Closes redmine ticket #2813 3. Fix failure on different type of args If a command was given a string argument where it expected an int, it would fail and the process would exit. Fix this by handling the exception caused in such cases. Closes redmine ticket #2812 --- python/suricata/sc/suricatasc.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/python/suricata/sc/suricatasc.py b/python/suricata/sc/suricatasc.py index 53a5b2f12f..6b81149ea8 100644 --- a/python/suricata/sc/suricatasc.py +++ b/python/suricata/sc/suricatasc.py @@ -212,18 +212,18 @@ class SuricataSC: phrase = " at least" if required_args_count != len(cmd_specs) else "" msg = "Missing arguments: expected{} {}".format(phrase, required_args_count) raise SuricataCommandException(msg) + except ValueError as ve: + raise SuricataCommandException("Erroneous arguments: {}".format(ve)) elif c < len(full_cmd): arguments[spec["name"]] = spec_type(full_cmd[c]) return cmd, arguments def parse_command(self, command): arguments = None - cmd = command.split(maxsplit=1)[0] if command else None + cmd = command.split()[0] if command else None if cmd in self.cmd_list: if cmd in self.fn_commands: cmd, arguments = getattr(self, "execute")(command=command) - else: - cmd = command else: raise SuricataCommandException("Unknown command {}".format(command)) return cmd, arguments