]> The Tcpdump Group git mirrors - tcpdump/blobdiff - print-nflog.c
CI: Add warning exemptions for Sun C (suncc-5.14) on Solaris 10
[tcpdump] / print-nflog.c
index bbe4ccfcc761b847d7e6043dc14e95dfc455cd94..0f5b8b8d6b11c72ab1518ac588069c1c0e810a1d 100644 (file)
 
 /* \summary: DLT_NFLOG printer */
 
-#ifdef HAVE_CONFIG_H
 #include <config.h>
-#endif
 
 #include "netdissect-stdinc.h"
 
+#define ND_LONGJMP_FROM_TCHECK
 #include "netdissect.h"
 #include "extract.h"
 
@@ -97,7 +96,7 @@ typedef struct nflog_timestamp {
 #define NFULA_PREFIX                   10      /* text string - null-terminated, count includes NUL */
 #define NFULA_UID                      11      /* UID owning socket on which packet was sent/received */
 #define NFULA_SEQ                      12      /* sequence number of packets on this NFLOG socket */
-#define NFULA_SEQ_GLOBAL               13      /* sequence number of pakets on all NFLOG sockets */
+#define NFULA_SEQ_GLOBAL               13      /* sequence number of packets on all NFLOG sockets */
 #define NFULA_GID                      14      /* GID owning socket on which packet was sent/received */
 #define NFULA_HWTYPE                   15      /* ARPHRD_ type of skbuff's device */
 #define NFULA_HWHEADER                 16      /* skbuff's MAC-layer header */
@@ -151,14 +150,11 @@ nflog_if_print(netdissect_options *ndo,
        u_int length = h->len;
 
        ndo->ndo_protocol = "nflog";
-       if (caplen < NFLOG_HDR_LEN) {
-               nd_print_trunc(ndo);
-               ndo->ndo_ll_hdr_len += caplen;
-               return;
-       }
-       ndo->ndo_ll_hdr_len += NFLOG_HDR_LEN;
+       ND_ICHECK_ZU(length, <, NFLOG_HDR_LEN);
 
        ND_TCHECK_SIZE(hdr);
+       ndo->ndo_ll_hdr_len += NFLOG_HDR_LEN;
+
        if (GET_U_1(hdr->nflog_version) != 0) {
                ND_PRINT("version %u (unknown)", GET_U_1(hdr->nflog_version));
                return;
@@ -171,26 +167,23 @@ nflog_if_print(netdissect_options *ndo,
        length -= NFLOG_HDR_LEN;
        caplen -= NFLOG_HDR_LEN;
 
-       while (length > 0) {
+       while (length != 0) {
                const nflog_tlv_t *tlv;
 
-               /* We have some data.  Do we have enough for the TLV header? */
-               if (caplen < NFLOG_TLV_LEN)
-                       goto trunc;     /* No. */
-
+               ND_ICHECK_ZU(length, <, NFLOG_TLV_LEN);
                tlv = (const nflog_tlv_t *) p;
+               /* Do we have enough data for the TLV header? */
                ND_TCHECK_SIZE(tlv);
                size = GET_HE_U_2(tlv->tlv_length);
                if (size % 4 != 0)
                        size += 4 - size % 4;
 
                /* Is the TLV's length less than the minimum? */
-               if (size < NFLOG_TLV_LEN)
-                       goto trunc;     /* Yes. Give up now. */
+               ND_ICHECK_ZU(size, <, NFLOG_TLV_LEN);
+               ND_ICHECK_U(length, <, size);
 
                /* Do we have enough data for the full TLV? */
-               if (caplen < size)
-                       goto trunc;     /* No. */
+               ND_TCHECK_LEN(tlv, size);
 
                if (GET_HE_U_2(tlv->tlv_type) == NFULA_PAYLOAD) {
                        /*
@@ -233,9 +226,9 @@ nflog_if_print(netdissect_options *ndo,
 
        ndo->ndo_ll_hdr_len += h_size - NFLOG_HDR_LEN;
        return;
-trunc:
-       nd_print_trunc(ndo);
-       ndo->ndo_ll_hdr_len += h_size - NFLOG_HDR_LEN;
+
+invalid:
+       nd_print_invalid(ndo);
 }
 
 #endif /* DLT_NFLOG */