From: Denis Ovsienko Date: Tue, 19 Jan 2021 16:25:27 +0000 (+0000) Subject: SCTP: Modernize packet parsing style. X-Git-Url: https://git.tcpdump.org/tcpdump/commitdiff_plain/3e9011fda0d9b36f699ebeb6ce91e6094c516236 SCTP: Modernize packet parsing style. Enable ND_LONGJMP_FROM_TCHECK. Report invalid packets as invalid. --- diff --git a/CHANGES b/CHANGES index 796500ec..ccca64b8 100644 --- a/CHANGES +++ b/CHANGES @@ -8,7 +8,7 @@ Monthday, Month DD, YYYY by gharris and denis Source code: Use %zu when printing a sizeof to squelch compiler warnings (FIXME: somebody please wrap the line below just before the release) - AODV, AppleTalk, BOOTP, EGP, EIGRP, Geneve, L2TP, NTP, OLSR, PGM, RIP, RSVP, TCP, UDP: Modernize packet parsing style + AODV, AppleTalk, BOOTP, EGP, EIGRP, Geneve, L2TP, NTP, OLSR, PGM, RIP, RSVP, SCTP, TCP, UDP: Modernize packet parsing style EGP: Replace custom code with tok2str() UDP: Clean up address and port printing. AppleTalk: Declutter appletalk.h. diff --git a/print-sctp.c b/print-sctp.c index ad0f7851..6a2a5b60 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" @@ -469,7 +470,7 @@ sctp_print(netdissect_options *ndo, { ND_PRINT("truncated-sctp - %zu bytes missing!", sizeof(struct sctpHeader) - sctpPacketLength); - return; + goto invalid; } sctpPktHdr = (const struct sctpHeader*) bp; ND_TCHECK_SIZE(sctpPktHdr); @@ -580,7 +581,7 @@ sctp_print(netdissect_options *ndo, if (chunkLengthRemaining < sizeof(*dataHdrPtr)) { ND_PRINT("bogus chunk length %u]", chunkLength); - return; + goto invalid; } dataHdrPtr=(const struct sctpDataPart*)bp; @@ -603,7 +604,7 @@ sctp_print(netdissect_options *ndo, payload_size = chunkLengthRemaining; if (payload_size == 0) { ND_PRINT("bogus chunk length %u]", chunkLength); - return; + goto invalid; } if (isforces) { @@ -639,7 +640,7 @@ sctp_print(netdissect_options *ndo, if (chunkLengthRemaining < sizeof(*init)) { ND_PRINT("bogus chunk length %u]", chunkLength); - return; + goto invalid; } init=(const struct sctpInitiation*)bp; ND_PRINT("[init tag: %u] ", GET_BE_U_4(init->initTag)); @@ -667,7 +668,7 @@ sctp_print(netdissect_options *ndo, if (chunkLengthRemaining < sizeof(*init)) { ND_PRINT("bogus chunk length %u]", chunkLength); - return; + goto invalid; } init=(const struct sctpInitiation*)bp; ND_PRINT("[init tag: %u] ", GET_BE_U_4(init->initTag)); @@ -698,7 +699,7 @@ sctp_print(netdissect_options *ndo, if (chunkLengthRemaining < sizeof(*sack)) { ND_PRINT("bogus chunk length %u]", chunkLength); - return; + goto invalid; } sack=(const struct sctpSelectiveAck*)bp; ND_PRINT("[cum ack %u] ", GET_BE_U_4(sack->highestConseqTSN)); @@ -716,7 +717,7 @@ sctp_print(netdissect_options *ndo, bp += sizeof(*frag), sctpPacketLengthRemaining -= sizeof(*frag), chunkLengthRemaining -= sizeof(*frag), fragNo++) { if (chunkLengthRemaining < sizeof(*frag)) { ND_PRINT("bogus chunk length %u]", chunkLength); - return; + goto invalid; } frag = (const struct sctpSelectiveFrag *)bp; ND_PRINT("\n\t\t[gap ack block #%u: start = %u, end = %u] ", @@ -731,7 +732,7 @@ sctp_print(netdissect_options *ndo, bp += 4, sctpPacketLengthRemaining -= 4, chunkLengthRemaining -= 4, tsnNo++) { if (chunkLengthRemaining < 4) { ND_PRINT("bogus chunk length %u]", chunkLength); - return; + goto invalid; } dupTSN = (const u_char *)bp; ND_PRINT("\n\t\t[dup TSN #%u: %u] ", tsnNo+1, @@ -769,7 +770,6 @@ sctp_print(netdissect_options *ndo, } } return; - -trunc: - nd_print_trunc(ndo); +invalid: + nd_print_invalid(ndo); }