Skip to content

Commit 20f3bce

Browse files
authored
Prevent integer overflow during PDU encoding (sonic-net#61)
Signed-off-by: Qi Luo <[email protected]>
1 parent d60afe1 commit 20f3bce

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/ax_interface/encodings.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -313,9 +313,9 @@ def to_bytes(self, endianness):
313313

314314
typed_bind = constants.ValueType(self.type_)
315315
if typed_bind in self.FOUR_BYTE_TYPES:
316-
byte_string += struct.pack(endianness + 'L', self.data)
316+
byte_string += struct.pack(endianness + 'L', self.data & 0x00000000ffffffff)
317317
elif typed_bind == constants.ValueType.COUNTER_64:
318-
byte_string += struct.pack(endianness + 'Q', self.data)
318+
byte_string += struct.pack(endianness + 'Q', self.data & 0xffffffffffffffff)
319319
elif typed_bind == constants.ValueType.OBJECT_IDENTIFIER or typed_bind in self.OCTET_STRINGS:
320320
byte_string += self.data.to_bytes(endianness)
321321
elif typed_bind in self.EMPTY_TYPES:

0 commit comments

Comments
 (0)