Skip to content

Commit b016347

Browse files
fennerfxlb
authored andcommitted
lwres: Fix an undefined behavior in pointer arithmetic
Check for truncation before doing pointer arithmetic to point to the end of the packet. print-lwres.c:294:10: runtime error: addition of unsigned offset to 0xf3b032be overflowed to 0x9652d560 SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior print-lwres.c:294:10 [Part of the PR #1012]
1 parent fc9abd5 commit b016347

File tree

4 files changed

+5
-1
lines changed

4 files changed

+5
-1
lines changed

print-lwres.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,9 @@ lwres_print(netdissect_options *ndo,
291291
if (ndo->ndo_vflag || v != LWRES_LWPACKETVERSION_0)
292292
ND_PRINT(" v%u", v);
293293
if (v != LWRES_LWPACKETVERSION_0) {
294-
s = bp + GET_BE_U_4(np->length);
294+
uint32_t pkt_len = GET_BE_U_4(np->length);
295+
ND_TCHECK_LEN(bp, pkt_len);
296+
s = bp + pkt_len;
295297
goto tail;
296298
}
297299

tests/TESTLIST

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -927,3 +927,4 @@ pb_nhrp_1 pb_nhrp_1.pcap pb_nhrp_1.out -v
927927
# Undefined behavior tests
928928
ip-snmp-leftshift-unsigned ip-snmp-leftshift-unsigned.pcap ip-snmp-leftshift-unsigned.out
929929
ip6-snmp-oid-unsigned ip6-snmp-oid-unsigned.pcap ip6-snmp-oid-unsigned.out
930+
lwres-pointer-arithmetic-ub lwres-pointer-arithmetic-ub.pcap lwres-pointer-arithmetic-ub.out

tests/lwres-pointer-arithmetic-ub.out

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
1 14:31:29.364332 IP6 fe80:0:10ff:15:1800:1a00:0:100.921 > a00:300:115:1800:1a00:f4:100:a00.0: lwres v41634 [|lwres]
283 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)