summaryrefslogtreecommitdiff
path: root/print-nflog.c
diff options
context:
space:
mode:
authorFrancois-Xavier Le Bail <devel.fx.lebail@orange.fr>2018-02-08 13:35:20 +0100
committerFrancois-Xavier Le Bail <devel.fx.lebail@orange.fr>2018-02-08 13:35:20 +0100
commit68707bd200fc99f2454ad89ace0d8ba1700b1732 (patch)
tree8e2d26402f20bea8dd951bd70540442d7864b0d3 /print-nflog.c
parentf253e110096ed673dc9de26da43ca80eaa2baec1 (diff)
downloadtcpdump-68707bd200fc99f2454ad89ace0d8ba1700b1732.tar.gz
NFLOG: Add some bounds checks
Moreover: Add and use tstr[]. Reduce the scope of the variable 'tlv'.
Diffstat (limited to 'print-nflog.c')
-rw-r--r--print-nflog.c36
1 files changed, 16 insertions, 20 deletions
diff --git a/print-nflog.c b/print-nflog.c
index d8328ec8..522d212c 100644
--- a/print-nflog.c
+++ b/print-nflog.c
@@ -34,6 +34,7 @@
#include "netdissect-stdinc.h"
#include "netdissect.h"
+static const char tstr[] = " [|nflog]";
#if defined(DLT_NFLOG) && defined(HAVE_PCAP_NFLOG_H)
#include <pcap/nflog.h>
@@ -71,17 +72,15 @@ nflog_if_print(netdissect_options *ndo,
const struct pcap_pkthdr *h, const u_char *p)
{
const nflog_hdr_t *hdr = (const nflog_hdr_t *)p;
- const nflog_tlv_t *tlv;
uint16_t size;
uint16_t h_size = sizeof(nflog_hdr_t);
u_int caplen = h->caplen;
u_int length = h->len;
- if (caplen < sizeof(nflog_hdr_t) || length < sizeof(nflog_hdr_t)) {
- ND_PRINT("[|nflog]");
- return h_size;
- }
+ if (caplen < sizeof(nflog_hdr_t) || length < sizeof(nflog_hdr_t))
+ goto trunc;
+ ND_TCHECK_SIZE(hdr);
if (hdr->nflog_version != 0) {
ND_PRINT("version %u (unknown)", hdr->nflog_version);
return h_size;
@@ -95,31 +94,25 @@ nflog_if_print(netdissect_options *ndo,
caplen -= sizeof(nflog_hdr_t);
while (length > 0) {
+ const nflog_tlv_t *tlv;
+
/* We have some data. Do we have enough for the TLV header? */
- if (caplen < sizeof(nflog_tlv_t) || length < sizeof(nflog_tlv_t)) {
- /* No. */
- ND_PRINT("[|nflog]");
- return h_size;
- }
+ if (caplen < sizeof(nflog_tlv_t) || length < sizeof(nflog_tlv_t))
+ goto trunc; /* No. */
tlv = (const nflog_tlv_t *) p;
+ ND_TCHECK_SIZE(tlv);
size = tlv->tlv_length;
if (size % 4 != 0)
size += 4 - size % 4;
/* Is the TLV's length less than the minimum? */
- if (size < sizeof(nflog_tlv_t)) {
- /* Yes. Give up now. */
- ND_PRINT("[|nflog]");
- return h_size;
- }
+ if (size < sizeof(nflog_tlv_t))
+ goto trunc; /* Yes. Give up now. */
/* Do we have enough data for the full TLV? */
- if (caplen < size || length < size) {
- /* No. */
- ND_PRINT("[|nflog]");
- return h_size;
- }
+ if (caplen < size || length < size)
+ goto trunc; /* No. */
if (tlv->tlv_type == NFULA_PAYLOAD) {
/*
@@ -163,6 +156,9 @@ nflog_if_print(netdissect_options *ndo,
}
return h_size;
+trunc:
+ ND_PRINT("%s", tstr);
+ return h_size;
}
#endif /* defined(DLT_NFLOG) && defined(HAVE_PCAP_NFLOG_H) */