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
pull/3661/head
Shivani Bhardwaj 7 years ago committed by Victor Julien
parent 27842c3750
commit b0b12021d3

@ -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

Loading…
Cancel
Save