Skip to content

Commit 2d2951a

Browse files
committed
DNS: Use ND_TCHECK_LEN() instead of a custom bounds check
This avoids an invalid-pointer-pair AddressSanitizer error. Add a test file. The error was: reading from file ppp_ip_udp_dns.pcap, link-type PPP_SERIAL(PPP over serial), snapshot length 2098998 ================================================================= ==258093==ERROR: AddressSanitizer: invalid-pointer-pair: 0x61300000c086 0x61300000019e #0 0x78274f in ns_rprint [...]/print-domain.c:728:9 Address 0x61300000c086 is a wild pointer inside of access range of size 0x000000000001. 0x61300000019e is located 0 bytes after 350-byte region [0x613000000040,0x61300000019e) allocated by thread T0 here: #0 0x4b997e in malloc ([...]/tcpdump+0x4b997e) #1 0x60220b in ppp_hdlc [...]/print-ppp.c:1367:16 SUMMARY: AddressSanitizer: invalid-pointer-pair [...]/print-domain.c:728:9 in ns_rprint
1 parent 5679db6 commit 2d2951a

File tree

4 files changed

+9
-4
lines changed

4 files changed

+9
-4
lines changed

print-domain.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -722,11 +722,10 @@ ns_rprint(netdissect_options *ndo,
722722
len = GET_BE_U_2(cp);
723723
cp += 2;
724724

725-
rp = cp + len;
726-
727725
ND_PRINT(" %s", tok2str(ns_type2str, "Type%u", typ));
728-
if (rp > ndo->ndo_snapend)
729-
return(NULL);
726+
727+
ND_TCHECK_LEN(cp, len);
728+
rp = cp + len;
730729

731730
switch (typ) {
732731
case T_A:
@@ -896,6 +895,9 @@ ns_rprint(netdissect_options *ndo,
896895
}
897896
}
898897
return (rp); /* XXX This isn't always right */
898+
899+
trunc:
900+
return(NULL);
899901
}
900902

901903
void

tests/TESTLIST

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,7 @@ dns_udp dns_udp.pcap dns_udp.out
359359
dns_udp-v dns_udp.pcap dns_udp-v.out -v
360360
dns_udp-vv dns_udp.pcap dns_udp-vv.out -vv
361361
dns_udp-vvv dns_udp.pcap dns_udp-vvv.out -vvv
362+
ppp_ip_udp_dns-vv ppp_ip_udp_dns.pcap ppp_ip_udp_dns.out -vv
362363
# tests with --skip option
363364
dns_tcp-skip-3 dns_tcp.pcap dns_tcp-skip-3.out --skip 3
364365
dns_tcp-skip-3-c-4 dns_tcp.pcap dns_tcp-skip-3-c-4.out --skip 3 -c 4

tests/ppp_ip_udp_dns.out

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
1 2037-11-24 07:59:58.999999 unknown PPP protocol (0x7e08): IP [total length 49441 > length 348] (invalid) (tos 0x0, ttl 64, id 1, offset 0, flags [none], proto UDP (17), length 49441, bad cksum 45ee (->13)!)
2+
69.168.178.248.53 > 192.168.0.111.1024: [bad udp cksum 0x33ea -> 0x73b6!] 0 [0q] [65535au] ar: . OPT UDPsize=26995 [Opt25701], . (Class 3584) Type0 [|domain]

tests/ppp_ip_udp_dns.pcap

393 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)