packet.ospf: workaround a bytearray vs buffer problem

feeding bytearray to struct.unpack() crashes on some environment.
(depends on the interpreter versions?  i'm not sure.)

this fixes the following crash in the unit test.
the crash was seen on travis-ci, too.
https://travis-ci.org/osrg/ryu/jobs/15578909
https://s3.amazonaws.com/archive.travis-ci.org/jobs/15578909/log.txt

======================================================================
ERROR: test_hello (packet.test_ospf.Test_ospf)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/yamamoto/git/ryu/ryu/tests/unit/packet/test_ospf.py", line 68, in test_hello
    msg2, cls, rest = ospf.OSPFMessage.parser(binmsg)
  File "/Users/yamamoto/git/ryu/ryu/lib/packet/ospf.py", line 443, in parser
    kwargs = subcls.parser(binmsg)
  File "/Users/yamamoto/git/ryu/ryu/lib/packet/ospf.py", line 501, in parser
    n = addrconv.ipv4.bin_to_text(n)
  File "/Users/yamamoto/git/ryu/ryu/lib/addrconv.py", line 30, in bin_to_text
    return str(self._addr(self._strat.packed_to_int(bin),
  File "/Users/yamamoto/git/ryu/.venv/lib/python2.7/site-packages/netaddr/strategy/ipv4.py", line 196, in packed_to_int
    return _struct.unpack('>I', packed_int)[0]
error: unpack requires a string argument of length 4

----------------------------------------------------------------------

Signed-off-by: YAMAMOTO Takashi <yamamoto@valinux.co.jp>
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
This commit is contained in:
YAMAMOTO Takashi 2013-12-18 12:21:04 +09:00 committed by FUJITA Tomonori
parent 5ac517ab36
commit d2bb2205de

View File

@ -498,7 +498,7 @@ class OSPFHello(OSPFMessage):
binneighbors = buf[cls._PACK_LEN:len(buf)]
while binneighbors:
n = binneighbors[:4]
n = addrconv.ipv4.bin_to_text(n)
n = addrconv.ipv4.bin_to_text(buffer(n))
binneighbors = binneighbors[4:]
neighbors.append(n)
return {