osmo_ipa: add extended checks

Make sure we properly handle None objects.

Change-Id: If5ddc04b8a5dc26e56e5f5bbec7f28cf0af4a97b
This commit is contained in:
Max 2018-11-26 19:01:30 +01:00
parent 04e7c64902
commit f0aa41e6a1
1 changed files with 5 additions and 1 deletions

View File

@ -106,8 +106,9 @@ class IPA(object):
Strip IPA protocol header correctly removing extension if present Strip IPA protocol header correctly removing extension if present
Returns data length, IPA protocol, extension (or None if not defined for a give protocol) and the data without header Returns data length, IPA protocol, extension (or None if not defined for a give protocol) and the data without header
""" """
if not len(data): if data == None or len(data) == 0:
return None, None, None, None return None, None, None, None
(dlen, proto) = struct.unpack('>HB', data[:3]) (dlen, proto) = struct.unpack('>HB', data[:3])
if self.PROTO['OSMO'] == proto or self.PROTO['CCM'] == proto: # there's extension which we have to unpack if self.PROTO['OSMO'] == proto or self.PROTO['CCM'] == proto: # there's extension which we have to unpack
return struct.unpack('>HBB', data[:4]) + (data[4:], ) # length, protocol, extension, data return struct.unpack('>HBB', data[:4]) + (data[4:], ) # length, protocol, extension, data
@ -117,6 +118,9 @@ class IPA(object):
""" """
Split the data which contains multiple concatenated IPA messages into tuple (first, rest) where rest contains remaining messages, first is the single IPA message Split the data which contains multiple concatenated IPA messages into tuple (first, rest) where rest contains remaining messages, first is the single IPA message
""" """
if data == None or len(data) == 0:
return None, None
(length, _, _, _) = self.del_header(data) (length, _, _, _) = self.del_header(data)
return data[:(length + 3)], data[(length + 3):] return data[:(length + 3)], data[(length + 3):]