X-Git-Url: https://git.tcpdump.org/tcpdump/blobdiff_plain/502befca57569b9c9ead4bcff5be674974515712..5f1caad63354a9066285cdc7be37eaa003c86cf4:/print-tcp.c diff --git a/print-tcp.c b/print-tcp.c index 7a04a6ff..f00ff325 100644 --- a/print-tcp.c +++ b/print-tcp.c @@ -189,8 +189,6 @@ tcp_print(netdissect_options *ndo, sport = EXTRACT_16BITS(&tp->th_sport); dport = EXTRACT_16BITS(&tp->th_dport); - hlen = TH_OFF(tp) * 4; - if (ip6) { if (ip6->ip6_nxt == IPPROTO_TCP) { ND_PRINT((ndo, "%s.%s > %s.%s: ", @@ -215,14 +213,16 @@ tcp_print(netdissect_options *ndo, } } + ND_TCHECK(*tp); + + hlen = TH_OFF(tp) * 4; + if (hlen < sizeof(*tp)) { ND_PRINT((ndo, " tcp %d [bad hdr length %u - too short, < %lu]", length - hlen, hlen, (unsigned long)sizeof(*tp))); return; } - ND_TCHECK(*tp); - seq = EXTRACT_32BITS(&tp->th_seq); ack = EXTRACT_32BITS(&tp->th_ack); win = EXTRACT_16BITS(&tp->th_win); @@ -541,7 +541,7 @@ tcp_print(netdissect_options *ndo, ND_PRINT((ndo, " keyid %d", *cp++)); datalen = len - 3; for (i = 0; i < datalen; ++i) { - LENCHECK(i); + LENCHECK(i + 1); ND_PRINT((ndo, "%02x", cp[i])); } break; @@ -609,7 +609,7 @@ tcp_print(netdissect_options *ndo, if (datalen) ND_PRINT((ndo, " 0x")); for (i = 0; i < datalen; ++i) { - LENCHECK(i); + LENCHECK(i + 1); ND_PRINT((ndo, "%02x", cp[i])); } break;