]> The Tcpdump Group git mirrors - tcpdump/blobdiff - print-sctp.c
Makefile.in: don't remove configure and config.h.in in make distclean.
[tcpdump] / print-sctp.c
index b5923ea6ed3c6739df90965fd2516cd3258c851a..cc5bee4ff6f4ebab7cb871e62bd433017dbd2fca 100644 (file)
@@ -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;
@@ -578,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);
@@ -600,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);
@@ -637,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));
@@ -665,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));
@@ -696,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));
@@ -714,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,
@@ -729,10 +712,7 @@ sctp_print(netdissect_options *ndo,
            for (tsnNo=0;
                 chunkLengthRemaining != 0 && tsnNo<GET_BE_U_2(sack->numDupTsns);
                 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));
@@ -769,7 +749,6 @@ sctp_print(netdissect_options *ndo,
       }
     }
     return;
-
-trunc:
-    nd_print_trunc(ndo);
+invalid:
+    nd_print_invalid(ndo);
 }