]> The Tcpdump Group git mirrors - tcpdump/commitdiff
SCTP: Modernize packet parsing style.
authorDenis Ovsienko <[email protected]>
Tue, 19 Jan 2021 16:25:27 +0000 (16:25 +0000)
committerDenis Ovsienko <[email protected]>
Wed, 20 Jan 2021 12:55:36 +0000 (12:55 +0000)
Enable ND_LONGJMP_FROM_TCHECK. Report invalid packets as invalid.

CHANGES
print-sctp.c

diff --git a/CHANGES b/CHANGES
index 796500ec147a753af00c22a32d2287ce1b735812..ccca64b80861624fc43e493c7dbf5fc0128a763a 100644 (file)
--- 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.
index ad0f7851889a5cc32dabb16e0f786dc8dc020be6..6a2a5b60a6b1818d3652d56ab67ff14d368ff2dd 100644 (file)
@@ -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);
 }