X-Git-Url: https://git.tcpdump.org/tcpdump/blobdiff_plain/ee68aa36460d7efeca48747f33b7f2adc0900bfb..refs/pull/1034/head:/print-sctp.c diff --git a/print-sctp.c b/print-sctp.c index e0c22076..cc5bee4f 100644 --- a/print-sctp.c +++ b/print-sctp.c @@ -41,6 +41,7 @@ #include "netdissect-stdinc.h" +#define ND_LONGJMP_FROM_TCHECK #include "netdissect.h" #include "addrtoname.h" #include "extract.h" @@ -451,7 +452,7 @@ void sctp_print(netdissect_options *ndo, const u_char *bp, /* beginning of sctp packet */ const u_char *bp2, /* beginning of enclosing */ - u_int sctpPacketLength) /* ip packet */ + u_int sctpPacketLength) /* sctp packet */ { u_int sctpPacketLengthRemaining; const struct sctpHeader *sctpPktHdr; @@ -465,12 +466,7 @@ sctp_print(netdissect_options *ndo, int isforces = 0; ndo->ndo_protocol = "sctp"; - if (sctpPacketLength < sizeof(struct sctpHeader)) - { - ND_PRINT("truncated-sctp - %ld bytes missing!", - (long)(sizeof(struct sctpHeader) - sctpPacketLength)); - return; - } + ND_ICHECKMSG_ZU("length", sctpPacketLength, <, sizeof(struct sctpHeader)); sctpPktHdr = (const struct sctpHeader*) bp; ND_TCHECK_SIZE(sctpPktHdr); sctpPacketLengthRemaining = sctpPacketLength; @@ -486,16 +482,15 @@ sctp_print(netdissect_options *ndo, if (ip6) { ND_PRINT("%s.%u > %s.%u: sctp", - ip6addr_string(ndo, ip6->ip6_src), + GET_IP6ADDR_STRING(ip6->ip6_src), sourcePort, - ip6addr_string(ndo, ip6->ip6_dst), + GET_IP6ADDR_STRING(ip6->ip6_dst), destPort); - } else - { + } else { ND_PRINT("%s.%u > %s.%u: sctp", - ipaddr_string(ndo, ip->ip_src), + GET_IPADDR_STRING(ip->ip_src), sourcePort, - ipaddr_string(ndo, ip->ip_dst), + GET_IPADDR_STRING(ip->ip_dst), destPort); } @@ -562,7 +557,7 @@ sctp_print(netdissect_options *ndo, const struct sctpDataPart *dataHdrPtr; uint8_t chunkFlg; uint32_t ppid; - u_int payload_size; + uint16_t payload_size; chunkFlg = GET_U_1(chunkDescPtr->chunkFlg); if ((chunkFlg & SCTP_DATA_UNORDERED) == SCTP_DATA_UNORDERED) @@ -579,10 +574,8 @@ sctp_print(netdissect_options *ndo, ((chunkFlg & SCTP_DATA_LAST_FRAG) == SCTP_DATA_LAST_FRAG) ) ND_PRINT(" "); - if (chunkLengthRemaining < sizeof(*dataHdrPtr)) { - ND_PRINT("bogus chunk length %u]", chunkLength); - return; - } + ND_ICHECKMSG_ZU("chunk length", chunkLengthRemaining, <, + sizeof(*dataHdrPtr)); dataHdrPtr=(const struct sctpDataPart*)bp; ppid = GET_BE_U_4(dataHdrPtr->payloadtype); @@ -601,11 +594,8 @@ sctp_print(netdissect_options *ndo, bp += sizeof(*dataHdrPtr); sctpPacketLengthRemaining -= sizeof(*dataHdrPtr); chunkLengthRemaining -= sizeof(*dataHdrPtr); + ND_ICHECKMSG_U("chunk length", chunkLengthRemaining, ==, 0); payload_size = chunkLengthRemaining; - if (payload_size == 0) { - ND_PRINT("bogus chunk length %u]", chunkLength); - return; - } if (isforces) { forces_print(ndo, bp, payload_size); @@ -638,10 +628,8 @@ sctp_print(netdissect_options *ndo, { const struct sctpInitiation *init; - if (chunkLengthRemaining < sizeof(*init)) { - ND_PRINT("bogus chunk length %u]", chunkLength); - return; - } + ND_ICHECKMSG_ZU("chunk length", chunkLengthRemaining, <, + sizeof(*init)); init=(const struct sctpInitiation*)bp; ND_PRINT("[init tag: %u] ", GET_BE_U_4(init->initTag)); ND_PRINT("[rwnd: %u] ", GET_BE_U_4(init->rcvWindowCredit)); @@ -666,10 +654,8 @@ sctp_print(netdissect_options *ndo, { const struct sctpInitiation *init; - if (chunkLengthRemaining < sizeof(*init)) { - ND_PRINT("bogus chunk length %u]", chunkLength); - return; - } + ND_ICHECKMSG_ZU("chunk length", chunkLengthRemaining, <, + sizeof(*init)); init=(const struct sctpInitiation*)bp; ND_PRINT("[init tag: %u] ", GET_BE_U_4(init->initTag)); ND_PRINT("[rwnd: %u] ", GET_BE_U_4(init->rcvWindowCredit)); @@ -697,10 +683,8 @@ sctp_print(netdissect_options *ndo, u_int fragNo, tsnNo; const u_char *dupTSN; - if (chunkLengthRemaining < sizeof(*sack)) { - ND_PRINT("bogus chunk length %u]", chunkLength); - return; - } + ND_ICHECKMSG_ZU("chunk length", chunkLengthRemaining, <, + sizeof(*sack)); sack=(const struct sctpSelectiveAck*)bp; ND_PRINT("[cum ack %u] ", GET_BE_U_4(sack->highestConseqTSN)); ND_PRINT("[a_rwnd %u] ", GET_BE_U_4(sack->updatedRwnd)); @@ -715,10 +699,8 @@ sctp_print(netdissect_options *ndo, for (fragNo=0; chunkLengthRemaining != 0 && fragNo < GET_BE_U_2(sack->numberOfdesc); bp += sizeof(*frag), sctpPacketLengthRemaining -= sizeof(*frag), chunkLengthRemaining -= sizeof(*frag), fragNo++) { - if (chunkLengthRemaining < sizeof(*frag)) { - ND_PRINT("bogus chunk length %u]", chunkLength); - return; - } + ND_ICHECKMSG_ZU("chunk length", chunkLengthRemaining, <, + sizeof(*frag)); frag = (const struct sctpSelectiveFrag *)bp; ND_PRINT("\n\t\t[gap ack block #%u: start = %u, end = %u] ", fragNo+1, @@ -730,10 +712,7 @@ sctp_print(netdissect_options *ndo, for (tsnNo=0; chunkLengthRemaining != 0 && tsnNonumDupTsns); bp += 4, sctpPacketLengthRemaining -= 4, chunkLengthRemaining -= 4, tsnNo++) { - if (chunkLengthRemaining < 4) { - ND_PRINT("bogus chunk length %u]", chunkLength); - return; - } + ND_ICHECKMSG_U("chunk length", chunkLengthRemaining, <, 4); dupTSN = (const u_char *)bp; ND_PRINT("\n\t\t[dup TSN #%u: %u] ", tsnNo+1, GET_BE_U_4(dupTSN)); @@ -770,7 +749,6 @@ sctp_print(netdissect_options *ndo, } } return; - -trunc: - nd_print_trunc(ndo); +invalid: + nd_print_invalid(ndo); }