]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
suricatasc: Fix command failures
authorShivani Bhardwaj <shivanib134@gmail.com>
Wed, 13 Feb 2019 11:02:06 +0000 (16:32 +0530)
committerVictor Julien <victor@inliniac.net>
Fri, 15 Feb 2019 09:56:58 +0000 (10:56 +0100)
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

index 53a5b2f12fc250bc34bff8cd210a7eae3aee579c..6b81149ea83b98d2224d3edf15c5d4311f11dee9 100644 (file)
@@ -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