X-Git-Url: https://git.tcpdump.org/tcpdump/blobdiff_plain/abc8c2d61c65757011d9d32abb01cd1e51232f3a..978dddc8fc393e7f36feacee6263f95b1d2c3fee:/print-ip.c diff --git a/print-ip.c b/print-ip.c index 47850f31..a0df9591 100644 --- a/print-ip.c +++ b/print-ip.c @@ -27,8 +27,6 @@ #include "netdissect-stdinc.h" -#include - #include "netdissect.h" #include "addrtoname.h" #include "extract.h" @@ -71,7 +69,7 @@ ip_printroute(netdissect_options *ndo, ND_PRINT(" [bad ptr %u]", GET_U_1(cp + 2)); for (len = 3; len < length; len += 4) { - ND_TCHECK_4(cp + len); + ND_TCHECK_4(cp + len); /* Needed to print the IP addresses */ ND_PRINT(" %s", GET_IPADDR_STRING(cp + len)); if (ptr > len) ND_PRINT(","); @@ -194,16 +192,7 @@ ip_printts(netdissect_options *ndo, case IPOPT_TS_TSANDADDR: ND_PRINT("TS+ADDR"); break; - /* - * prespecified should really be 3, but some ones might send 2 - * instead, and the IPOPT_TS_PRESPEC constant can apparently - * have both values, so we have to hard-code it here. - */ - - case 2: - ND_PRINT("PRESPEC2.0"); - break; - case 3: /* IPOPT_TS_PRESPEC */ + case IPOPT_TS_PRESPEC: ND_PRINT("PRESPEC"); break; default: @@ -482,8 +471,18 @@ ip_print(netdissect_options *ndo, GET_IPADDR_STRING(ip->ip_src), GET_IPADDR_STRING(ip->ip_dst)); } + /* + * Do a bounds check before calling ip_demux_print(). + * At least the header data is required. + */ + if (!ND_TTEST_LEN((const u_char *)ip, hlen)) { + ND_PRINT(" [remaining caplen(%u) < header length(%u)]", + ND_BYTES_AVAILABLE_AFTER((const u_char *)ip), + hlen); + nd_trunc_longjmp(ndo); + } ip_demux_print(ndo, (const u_char *)ip + hlen, len, 4, - off & IP_MF, GET_U_1(ip->ip_ttl), nh, bp); + off & IP_MF, GET_U_1(ip->ip_ttl), nh, bp); } else { /* * Ultra quiet now means that all this stuff should be @@ -511,7 +510,6 @@ ip_print(netdissect_options *ndo, trunc: nd_print_trunc(ndo); - return; } void