]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
capture: use uint16_t for max_pending_packets
authorJason Ish <jason.ish@oisf.net>
Wed, 3 May 2023 21:21:26 +0000 (15:21 -0600)
committerVictor Julien <vjulien@oisf.net>
Fri, 5 May 2023 08:22:47 +0000 (10:22 +0200)
Use a fixed type of max_pending_packets instead of intmax_t which can
differ based on the platform/standard library.

Should also prevent lints about possible arithmetic overflow.

17 files changed:
src/runmode-af-packet.c
src/runmode-netmap.c
src/runmode-unittests.c
src/source-af-packet.c
src/source-erf-dag.c
src/source-ipfw.c
src/source-napatech.c
src/source-nfq.c
src/source-pcap-file-helper.c
src/source-pcap-file.c
src/source-pfring.c
src/suricata.c
src/tests/fuzz/fuzz_decodepcapfile.c
src/tests/fuzz/fuzz_predefpcap_aware.c
src/tests/fuzz/fuzz_sigpcap.c
src/tests/fuzz/fuzz_sigpcap_aware.c
src/tmqh-packetpool.c

index 6f3d77adff3044810068905163b038273c2e1682..4c777b90e9078083d6802c5105b9a62377e3c281 100644 (file)
@@ -59,7 +59,7 @@
 #include "source-af-packet.h"
 #include "util-bpf.h"
 
-extern intmax_t max_pending_packets;
+extern uint16_t max_pending_packets;
 
 const char *RunModeAFPGetDefaultMode(void)
 {
index b961bb5713d5eb33636d4e1fb258287513d53c0b..5110a820eef93502b82084288b9a0fcb8c7459d2 100644 (file)
@@ -50,7 +50,7 @@
 #include "suricata.h"
 #include "util-bpf.h"
 
-extern intmax_t max_pending_packets;
+extern uint16_t max_pending_packets;
 
 const char *RunModeNetmapGetDefaultMode(void)
 {
index 22571f3aa330f00e1585f01d1e7fa6965aad6fa1..af8a7cd8ad4a1e63c931a4eb0f1382f9b8cd4571 100644 (file)
@@ -278,7 +278,7 @@ void RunUnittests(int list_unittests, const char *regex_arg)
         UtListTests(regex_arg);
     } else {
         /* global packet pool */
-        extern intmax_t max_pending_packets;
+        extern uint16_t max_pending_packets;
         max_pending_packets = 128;
         PacketPoolInit();
 
index f442e079bf73ae15b1d817c74763a3ed30cce2b0..f1183dd7b8d33f89a8a31ab3b7ba128d59085fcd 100644 (file)
@@ -118,7 +118,7 @@ struct bpf_program {
 
 #endif /* HAVE_AF_PACKET */
 
-extern intmax_t max_pending_packets;
+extern uint16_t max_pending_packets;
 
 #ifndef HAVE_AF_PACKET
 
index 3ac466b2c2d5cb57159a00f3236500ea10e69e8d..9dde3a644bc92d7651f7172afa812c5541293dfc 100644 (file)
@@ -89,7 +89,7 @@ NoErfDagSupportExit(ThreadVars *tv, const void *initdata, void **data)
 /* Number of bytes per loop to process before fetching more data. */
 #define BYTES_PER_LOOP (4 * 1024 * 1024) /* 4 MB */
 
-extern intmax_t max_pending_packets;
+extern uint16_t max_pending_packets;
 
 typedef struct ErfDagThreadVars_ {
     ThreadVars *tv;
index 0aa71b42502ff7b69b3c9d30037c7e9a772bd3e0..10ed26f78ac16008153256aaa6fd26c2aef4de6b 100644 (file)
@@ -102,7 +102,7 @@ TmEcode NoIPFWSupportExit(ThreadVars *tv, const void *initdata, void **data)
 
 #include "action-globals.h"
 
-extern intmax_t max_pending_packets;
+extern uint16_t max_pending_packets;
 
 /**
  * \brief Structure to hold thread specific variables.
index aab58e9b02ae299c070c76400275e070ec0d1c47..90ff4c328e9d9f7b571a69b6df63ef1fe3fc43bb 100644 (file)
@@ -79,7 +79,7 @@ TmEcode NoNapatechSupportExit(ThreadVars *tv, const void *initdata, void **data)
 #include <numa.h>
 #include <nt.h>
 
-extern intmax_t max_pending_packets;
+extern uint16_t max_pending_packets;
 
 typedef struct NapatechThreadVars_
 {
index d7222da694e2c9a2e43b573dae5541864417a11c..2262f10730f989c9d92ca2094d588427780288dc 100644 (file)
@@ -97,7 +97,7 @@ static TmEcode NoNFQSupportExit(ThreadVars *tv, const void *initdata, void **dat
 
 #else /* we do have NFQ support */
 
-extern intmax_t max_pending_packets;
+extern uint16_t max_pending_packets;
 
 #define MAX_ALREADY_TREATED 5
 #define NFQ_VERDICT_RETRY_COUNT 3
index 5cae38dfdaea57666acb7241a7cee327bad911d8..de78fc45f1f233e70f00fcca8fd82da66e05ea9b 100644 (file)
@@ -31,7 +31,7 @@
 #include "source-pcap-file.h"
 #include "util-exception-policy.h"
 
-extern intmax_t max_pending_packets;
+extern uint16_t max_pending_packets;
 extern PcapFileGlobalVars pcap_g;
 
 static void PcapFileCallbackLoop(char *user, struct pcap_pkthdr *h, u_char *pkt);
index e4d77ca4918bf8d4399dbf4949ea101d02ed6785..f60b94b9815a427992fa8aac0cf56f008a5e0b2f 100644 (file)
@@ -32,7 +32,7 @@
 #include "runmode-unix-socket.h"
 #include "suricata.h"
 
-extern intmax_t max_pending_packets;
+extern uint16_t max_pending_packets;
 PcapFileGlobalVars pcap_g;
 
 /**
index 86260b3ab74e1f82f821d8b223341f451b58962c..96da94eff5334564d1e0fd9d8040058f15ed750b 100644 (file)
@@ -57,7 +57,7 @@ TmEcode DecodePfringThreadInit(ThreadVars *, const void *, void **);
 TmEcode DecodePfring(ThreadVars *, Packet *, void *);
 TmEcode DecodePfringThreadDeinit(ThreadVars *tv, void *data);
 
-extern intmax_t max_pending_packets;
+extern uint16_t max_pending_packets;
 
 #ifndef HAVE_PFRING
 
index 78c92e0ae798ed13b6d8fc01418980a6793e56a2..ea5652f65c1a43fcda1eb0bf7767be0589527ca3 100644 (file)
@@ -176,7 +176,7 @@ static enum EngineMode g_engine_mode = ENGINE_MODE_UNKNOWN;
 uint8_t host_mode = SURI_HOST_IS_SNIFFER_ONLY;
 
 /** Maximum packets to simultaneously process. */
-intmax_t max_pending_packets;
+uint16_t max_pending_packets;
 
 /** global indicating if detection is enabled */
 int g_detect_disabled = 0;
@@ -2426,16 +2426,19 @@ static int ConfigGetCaptureValue(SCInstance *suri)
 {
     /* Pull the max pending packets from the config, if not found fall
      * back on a sane default. */
-    if (ConfGetInt("max-pending-packets", &max_pending_packets) != 1)
-        max_pending_packets = DEFAULT_MAX_PENDING_PACKETS;
-    if (max_pending_packets >= 65535) {
-        SCLogError("Maximum max-pending-packets setting is 65534. "
+    intmax_t tmp_max_pending_packets;
+    if (ConfGetInt("max-pending-packets", &tmp_max_pending_packets) != 1)
+        tmp_max_pending_packets = DEFAULT_MAX_PENDING_PACKETS;
+    if (tmp_max_pending_packets < 1 || tmp_max_pending_packets >= UINT16_MAX) {
+        SCLogError("Maximum max-pending-packets setting is 65534 and must be greater than 0. "
                    "Please check %s for errors",
                 suri->conf_filename);
         return TM_ECODE_FAILED;
+    } else {
+        max_pending_packets = (uint16_t)tmp_max_pending_packets;
     }
 
-    SCLogDebug("Max pending packets set to %"PRIiMAX, max_pending_packets);
+    SCLogDebug("Max pending packets set to %" PRIu16, max_pending_packets);
 
     /* Pull the default packet size from the config, if not found fall
      * back on a sane default. */
index 9685ea51060c7663db3f7bb76b44b7437b1eb8f9..c4f2266a6560f7d1e58cb56d1242de43526e4c23 100644 (file)
@@ -77,7 +77,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
         tmm_modules[TMM_DECODEPCAPFILE].ThreadInit(tv, NULL, (void **) &dtv);
         (void)SC_ATOMIC_SET(tv->tm_slots->slot_next->slot_data, dtv);
 
-        extern intmax_t max_pending_packets;
+        extern uint16_t max_pending_packets;
         max_pending_packets = 128;
         PacketPoolInit();
 
index 80228edb689c0d7ddd3819ca6f90f64f8b172511..de0aa45f256be1977d0c9a361f90e77b24f1655d 100644 (file)
@@ -96,7 +96,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
         tmm_modules[TMM_FLOWWORKER].ThreadInit(&tv, NULL, &fwd);
         StatsSetupPrivate(&tv);
 
-        extern intmax_t max_pending_packets;
+        extern uint16_t max_pending_packets;
         max_pending_packets = 128;
         PacketPoolInit();
         if (DetectEngineReload(&surifuzz) < 0) {
index 5def9096ae88f41c2beb02dbf04456b9301eea89..dfebd1f5f6da63f67cb555b6db795bd9192299fe 100644 (file)
@@ -89,7 +89,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
         tmm_modules[TMM_FLOWWORKER].ThreadInit(&tv, NULL, &fwd);
         StatsSetupPrivate(&tv);
 
-        extern intmax_t max_pending_packets;
+        extern uint16_t max_pending_packets;
         max_pending_packets = 128;
         PacketPoolInit();
         initialized = 1;
index 9c2930ec40768faab7ed9da24083c5ed0eeb450f..d025e78e5712105f14f701843cff6cda7bb660ff 100644 (file)
@@ -115,7 +115,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
         tmm_modules[TMM_FLOWWORKER].ThreadInit(&tv, NULL, &fwd);
         StatsSetupPrivate(&tv);
 
-        extern intmax_t max_pending_packets;
+        extern uint16_t max_pending_packets;
         max_pending_packets = 128;
         PacketPoolInit();
         initialized = 1;
index 431fa2956e72c7a529cc60b731decd2d181331c9..174bc4c38e7b2d741b6a4ea7340412aab9aafa0d 100644 (file)
@@ -283,7 +283,7 @@ void PacketPoolInitEmpty(void)
 
 void PacketPoolInit(void)
 {
-    extern intmax_t max_pending_packets;
+    extern uint16_t max_pending_packets;
 
     PktPool *my_pool = GetThreadPacketPool();
 
@@ -499,8 +499,8 @@ void TmqhReleasePacketsToPacketPool(PacketQueue *pq)
  */
 void PacketPoolPostRunmodes(void)
 {
-    extern intmax_t max_pending_packets;
-    intmax_t pending_packets = max_pending_packets;
+    extern uint16_t max_pending_packets;
+    uint16_t pending_packets = max_pending_packets;
     if (pending_packets < RESERVED_PACKETS) {
         FatalError("'max-pending-packets' setting "
                    "must be at least %d",