Serialized data version check.

This commit is contained in:
Aldo Cortesi 2012-04-11 10:10:53 +12:00
parent 5e096c8ec9
commit 8c96264304
2 changed files with 15 additions and 1 deletions

View File

@ -1575,6 +1575,9 @@ class FlowReader:
try:
while 1:
data = tnetstring.load(self.fo)
if tuple(data["version"]) != version.IVERSION:
v = ".".join(str(i) for i in data["version"])
raise FlowReadError("Incompatible serialized data version: %s"%v)
off = self.fo.tell()
yield Flow._from_state(data)
except ValueError:

View File

@ -1,7 +1,7 @@
import Queue, time
from cStringIO import StringIO
import email.utils
from libmproxy import filt, flow, controller, utils
from libmproxy import filt, flow, controller, utils, tnetstring
import tutils
import libpry
@ -494,6 +494,17 @@ class uSerialize(libpry.AutoTree):
f = flow.FlowReadError("foo")
assert f.strerror == "foo"
def test_versioncheck(self):
f = tutils.tflow()
d = f._get_state()
d["version"] = (0, 0)
sio = StringIO()
tnetstring.dump(d, sio)
sio.seek(0)
r = flow.FlowReader(sio)
libpry.raises("version", list, r.stream())
class uFlowMaster(libpry.AutoTree):
def test_load_script(self):