Skip to content

Commit 5b75126

Browse files
authored
RTPS: Pack count field of ACKNACK submessage correctly (#3915)
* Pack count field of ACKNACK submessage correctly The count field of ACKNACK submessage is an integer field and should be packed using the endianness flag, just like how the count field of HEARTBEAT submessage is handled. Currently, `count=1` is incorrectly packed as `"\x00\x00\x00\x01"` (== 16777216), regardless of the endianness bit. With this change, `count=1` is correctly packed as `"\x01\x00\x00\x00"` (== 1), given the endianness is set. * add a unit test Signed-off-by: Seulbae Kim <squizz617@gmail.com> --------- Signed-off-by: Seulbae Kim <squizz617@gmail.com>
1 parent 56c01c6 commit 5b75126

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

scapy/contrib/rtps/rtps.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,8 @@ class RTPSSubMessage_ACKNACK(EPacket):
351351
"readerSNState",
352352
0, length_from=lambda pkt: pkt.octetsToNextHeader - 8 - 4
353353
),
354-
XNBytesField("count", 0, 4),
354+
EField(IntField("count", 0),
355+
endianness_from=e_flags),
355356
]
356357

357358

test/contrib/rtps.uts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -443,3 +443,36 @@ p1 = RTPS(
443443
assert p0.build() == d
444444
assert p1.build() == d
445445
assert p0 == p1
446+
447+
+ Test for pr #3915
448+
= RTPS ACKNACK count packing and dissection
449+
450+
d = b"\x52\x54\x50\x53\x02\x02\x01\x0f\x01\x0f\x45\xd2\xb3\xf5\x58\xb9" \
451+
b"\x01\x00\x00\x00\x06\x03\x18\x00\x00\x00\x03\xc7\x00\x00\x03\xc2" \
452+
b"\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00"
453+
p0 = RTPS(d)
454+
455+
p1 = RTPS(
456+
protocolVersion=ProtocolVersionPacket(major=2, minor=2),
457+
vendorId=VendorIdPacket(vendor_id=0x010f),
458+
guidPrefix=GUIDPrefixPacket(
459+
hostId=0x010f45d2, appId=0xb3f558b9, instanceId=0x01000000
460+
),
461+
magic=b"RTPS",
462+
) / RTPSMessage(
463+
submessages=[
464+
RTPSSubMessage_ACKNACK(
465+
submessageId=6,
466+
submessageFlags=3,
467+
octetsToNextHeader=0x18,
468+
reader_id=b'\x00\x00\x03\xc7',
469+
writer_id=b'\x00\x00\x03\xc2',
470+
readerSNState=b'\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00',
471+
count=1
472+
)
473+
]
474+
)
475+
476+
assert p0.build() == d
477+
assert p1.build() == d
478+
assert p0 == p1

0 commit comments

Comments
 (0)