]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
pcap: fix buffer size validation logic
authorVictor Julien <victor@inliniac.net>
Tue, 23 Oct 2018 12:51:25 +0000 (14:51 +0200)
committerVictor Julien <victor@inliniac.net>
Thu, 1 Nov 2018 14:46:10 +0000 (15:46 +0100)
src/runmode-pcap.c
src/source-pcap.c

index 684218acba7c14bd9a06d7700215f1580f75cecd..31e0f63af11dd16fcea5fdb7b5fcdfb0b013ea0e 100644 (file)
@@ -99,8 +99,14 @@ static void *ParsePcapConfig(const char *iface)
     aconf->buffer_size = 0;
     /* If set command line option has precedence over config */
     if ((ConfGetInt("pcap.buffer-size", &value)) == 1) {
-        SCLogInfo("Pcap will use %d buffer size", (int)value);
-        aconf->buffer_size = value;
+        if (value >= 0 && value <= INT_MAX) {
+            SCLogInfo("Pcap will use %d buffer size", (int)value);
+            aconf->buffer_size = value;
+        } else {
+            SCLogWarning(SC_ERR_INVALID_ARGUMENT, "pcap.buffer-size "
+                    "value of %"PRIiMAX" is invalid. Valid range is "
+                    "0-2147483647", value);
+        }
     }
 
     aconf->checksum_mode = CHECKSUM_VALIDATION_AUTO;
index 84e945673588d90b277d06ace9dd27ec1f77bb6c..05186add1b63300140dc138121d7a1ac9f7e2651 100644 (file)
@@ -420,9 +420,8 @@ TmEcode ReceivePcapThreadInit(ThreadVars *tv, const void *initdata, void **data)
     }
 #ifdef HAVE_PCAP_SET_BUFF
     ptv->pcap_buffer_size = pcapconfig->buffer_size;
-    if (ptv->pcap_buffer_size >= 0 && ptv->pcap_buffer_size <= INT_MAX) {
-        if (ptv->pcap_buffer_size > 0)
-            SCLogInfo("Going to use pcap buffer size of %" PRId32 "", ptv->pcap_buffer_size);
+    if (ptv->pcap_buffer_size > 0) {
+        SCLogInfo("Going to use pcap buffer size of %" PRId32 "", ptv->pcap_buffer_size);
 
         int pcap_set_buffer_size_r = pcap_set_buffer_size(ptv->pcap_handle,ptv->pcap_buffer_size);
         //printf("ReceivePcapThreadInit: pcap_set_timeout(%p) returned %" PRId32 "\n", ptv->pcap_handle, pcap_set_buffer_size_r);