X-Git-Url: https://git.tcpdump.org/tcpdump/blobdiff_plain/ed85e20e4d6a27d5405f37366dd34b64c10a9211..a890c4489fa1bcee9f455ee28d772bb1ccf590bf:/print-udp.c diff --git a/print-udp.c b/print-udp.c index f3da50c9..c3edf6ef 100644 --- a/print-udp.c +++ b/print-udp.c @@ -43,7 +43,6 @@ #include "nameser.h" #include "nfs.h" -#include "bootp.h" struct rtcphdr { uint16_t rh_flags; /* T:2 P:1 CNT:5 PT:8 */ @@ -368,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]")); @@ -383,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; @@ -442,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: @@ -571,7 +573,7 @@ udp_print(netdissect_options *ndo, register const u_char *bp, u_int length, timed_print(ndo, (const u_char *)(up + 1)); else if (ISPORT(TFTP_PORT)) tftp_print(ndo, (const u_char *)(up + 1), length); - else if (ISPORT(IPPORT_BOOTPC) || ISPORT(IPPORT_BOOTPS)) + else if (ISPORT(BOOTPC_PORT) || ISPORT(BOOTPS_PORT)) bootp_print(ndo, (const u_char *)(up + 1), length); else if (ISPORT(RIP_PORT)) rip_print(ndo, (const u_char *)(up + 1), length); @@ -636,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); @@ -676,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)); + } }