Parse fix for trace

This commit is contained in:
Kkevsterrr 2019-12-13 07:28:25 -05:00
parent 255ef9e5d8
commit 67414cb3e5
2 changed files with 9 additions and 7 deletions

View File

@ -65,14 +65,15 @@ class TraceAction(Action):
"""
Parses a string representation for this object.
"""
if not string:
return False
try:
if string:
self.start_ttl, self.end_ttl = string.split(":")
self.start_ttl = int(self.start_ttl)
self.end_ttl = int(self.end_ttl)
if self.start_ttl > self.end_ttl:
logger.error("Cannot use a trace with a start ttl greater than end_ttl (%d > %d)" % (self.start_ttl, self.end_ttl))
return False
self.start_ttl, self.end_ttl = string.split(":")
self.start_ttl = int(self.start_ttl)
self.end_ttl = int(self.end_ttl)
if self.start_ttl > self.end_ttl:
logger.error("Cannot use a trace with a start ttl greater than end_ttl (%d > %d)" % (self.start_ttl, self.end_ttl))
return False
except ValueError:
logger.exception("Cannot parse ttls from given data %s" % string)
return False

View File

@ -91,3 +91,4 @@ def test_trace_parse_handling():
print("Testing incorrect parsing:")
assert not actions.trace.TraceAction().parse("5:4", logger)
assert not actions.trace.TraceAction().parse("THISHOULDFAIL", logger)
assert not actions.trace.TraceAction().parse("", logger)