Skip to content

Commit 873b872

Browse files
committed
IP: Use ND_TTEST_LEN() instead of a custom bounds check
This avoids an invalid-pointer-pair AddressSanitizer error with options -fsanitize=address -fsanitize=pointer-compare and ASAN_OPTIONS=detect_invalid_pointer_pairs=1 The error was: ip_printroute_asan : TEST FAILED[...] reading from file ip_printroute_asan.pcap, link-type EN10MB (Ethernet), snapshot length 60 ================================================================= ==ERROR: AddressSanitizer: invalid-pointer-pair: 0x60600000006a 0x60600000005c #0 0x558ce1cddb0b in ip_print /home/cpe/soft-origin/tcpdump/my-tcpdump/print-ip.c:429:55 0x60600000006a is located 14 bytes after 60-byte region [0x606000000020,0x60600000005c) allocated by thread T0 here: #0 0x558ce1c5390e in malloc (/home/cpe/soft-origin/tcpdump/my-tcpdump/tcpdump+0x1fd90e) #1 0x558ce1efbba3 in pcap_check_header /home/cpe/soft-origin/tcpdump/my-libpcap/sf-pcap.c:480:14 0x60600000005c is located 0 bytes after 60-byte region [0x606000000020,0x60600000005c) allocated by thread T0 here: #0 0x558ce1c5390e in malloc (/home/cpe/soft-origin/tcpdump/my-tcpdump/tcpdump+0x1fd90e) #1 0x558ce1efbba3 in pcap_check_header /home/cpe/soft-origin/tcpdump/my-libpcap/sf-pcap.c:480:14 SUMMARY: AddressSanitizer: invalid-pointer-pair /home/cpe/soft-origin/tcpdump/my-tcpdump/print-ip.c:429:55 in ip_print
1 parent dad8c2e commit 873b872

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

print-ip.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,7 @@ ip_print(netdissect_options *ndo,
426426
ND_PRINT(")");
427427
}
428428

429-
if (!ndo->ndo_Kflag && (const u_char *)ip + hlen <= ndo->ndo_snapend) {
429+
if (!ndo->ndo_Kflag && ND_TTEST_LEN((const u_char *)ip, hlen)) {
430430
vec[0].ptr = (const uint8_t *)(const void *)ip;
431431
vec[0].len = hlen;
432432
sum = in_cksum(vec, 1);

0 commit comments

Comments
 (0)