Make mitmdump handle invalid serialized data gracefully.

This commit is contained in:
Aldo Cortesi
2011-03-11 15:16:31 +13:00
parent 7d85db0da3
commit 9f16a84a9e
3 changed files with 21 additions and 5 deletions

View File

@@ -560,6 +560,10 @@ class FlowWriter:
s = json.dumps(d)
self.ns.write(s)
class FlowReadError(Exception):
@property
def strerror(self):
return self.args[0]
class FlowReader:
def __init__(self, fo):
@@ -570,7 +574,10 @@ class FlowReader:
"""
Yields Flow objects from the dump.
"""
for i in self.ns:
data = json.loads(i)
yield Flow.from_state(data)
try:
for i in self.ns:
data = json.loads(i)
yield Flow.from_state(data)
except netstring.DecoderError:
raise FlowReadError("Invalid data format.")