packet: Avoid parsing an empty buffer

For example, the packet library detects the TCP payload type by using
the TCP src/dst port, but in case of the BGP packet, the packet
library will try to parse a TCP ACK packet as a BGP packet, and will
fail to parse.

This patch enables to ignore an empty buffer and fixes this problem.

Signed-off-by: IWASE Yusuke <iwase.yusuke0@gmail.com>
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
This commit is contained in:
IWASE Yusuke 2016-09-27 14:25:21 +09:00 committed by FUJITA Tomonori
parent 51e0abd365
commit 35973fcc20
1 changed files with 3 additions and 0 deletions

View File

@ -69,6 +69,9 @@ class Packet(StringifyMixin):
def _parser(self, cls):
rest_data = self.data
while cls:
# Ignores an empty buffer
if not six.binary_type(rest_data).strip(b'\x00'):
break
try:
proto, cls, rest_data = cls.parser(rest_data)
except struct.error: