X-Git-Url: https://git.tcpdump.org/tcpdump/blobdiff_plain/f2e17bb1673b6c1c9d62ea51625aef920d7252d2..refs/pull/433/head:/print-udp.c diff --git a/print-udp.c b/print-udp.c index 54d050c2..c3edf6ef 100644 --- a/print-udp.c +++ b/print-udp.c @@ -367,7 +367,6 @@ udp_print(netdissect_options *ndo, register const u_char *bp, u_int length, else ip6 = NULL; #endif /*INET6*/ - cp = (u_char *)(up + 1); if (!ND_TTEST(up->uh_dport)) { udpipaddr_print(ndo, ip, -1, -1); ND_PRINT((ndo, "[|udp]")); @@ -382,20 +381,24 @@ udp_print(netdissect_options *ndo, register const u_char *bp, u_int length, ND_PRINT((ndo, "truncated-udp %d", length)); return; } + ulen = EXTRACT_16BITS(&up->uh_ulen); + if (ulen < sizeof(struct udphdr)) { + udpipaddr_print(ndo, ip, sport, dport); + ND_PRINT((ndo, "truncated-udplength %d", ulen)); + return; + } + ulen -= sizeof(struct udphdr); length -= sizeof(struct udphdr); + if (ulen < length) + length = ulen; + cp = (u_char *)(up + 1); if (cp > ndo->ndo_snapend) { udpipaddr_print(ndo, ip, sport, dport); ND_PRINT((ndo, "[|udp]")); return; } - ulen = EXTRACT_16BITS(&up->uh_ulen); - if (ulen < 8) { - udpipaddr_print(ndo, ip, sport, dport); - ND_PRINT((ndo, "truncated-udplength %d", ulen)); - return; - } if (ndo->ndo_packettype) { register struct sunrpc_msg *rp; enum sunrpc_msg_type direction; @@ -441,7 +444,7 @@ udp_print(netdissect_options *ndo, register const u_char *bp, u_int length, case PT_CNFP: udpipaddr_print(ndo, ip, sport, dport); - cnfp_print(ndo, cp, (const u_char *)ip); + cnfp_print(ndo, cp); break; case PT_TFTP: @@ -635,7 +638,8 @@ udp_print(netdissect_options *ndo, register const u_char *bp, u_int length, else if (ISPORT(RADIUS_PORT) || ISPORT(RADIUS_NEW_PORT) || ISPORT(RADIUS_ACCOUNTING_PORT) || - ISPORT(RADIUS_NEW_ACCOUNTING_PORT) ) + ISPORT(RADIUS_NEW_ACCOUNTING_PORT) || + ISPORT(RADIUS_COA_PORT) ) radius_print(ndo, (const u_char *)(up+1), length); else if (dport == HSRP_PORT) hsrp_print(ndo, (const u_char *)(up + 1), length); @@ -675,12 +679,23 @@ udp_print(netdissect_options *ndo, register const u_char *bp, u_int length, otv_print(ndo, (const u_char *)(up + 1), length); else if (ISPORT(VXLAN_PORT)) vxlan_print(ndo, (const u_char *)(up + 1), length); - else - ND_PRINT((ndo, "UDP, length %u", - (uint32_t)(ulen - sizeof(*up)))); + else if (ISPORT(GENEVE_PORT)) + geneve_print(ndo, (const u_char *)(up + 1), length); + else { + if (ulen > length) + ND_PRINT((ndo, "UDP, bad length %u > %u", + ulen, length)); + else + ND_PRINT((ndo, "UDP, length %u", ulen)); + } #undef ISPORT - } else - ND_PRINT((ndo, "UDP, length %u", (uint32_t)(ulen - sizeof(*up)))); + } else { + if (ulen > length) + ND_PRINT((ndo, "UDP, bad length %u > %u", + ulen, length)); + else + ND_PRINT((ndo, "UDP, length %u", ulen)); + } }