]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
gcc7: fix format-truncation warnings in runmodes
authorVictor Julien <victor@inliniac.net>
Thu, 13 Jul 2017 07:57:40 +0000 (09:57 +0200)
committerVictor Julien <victor@inliniac.net>
Thu, 13 Jul 2017 07:57:40 +0000 (09:57 +0200)
Example:

util-runmodes.c: In function ‘RunModeSetIPSAutoFp’:
util-runmodes.c:496:40: error: ‘snprintf’ output may be truncated before the last format character [-Werror=format-truncation=]
         snprintf(qname, sizeof(qname), "pickup%d", thread+1);
                                        ^~~~~~~~~~
util-runmodes.c:496:9: note: ‘snprintf’ output between 8 and 17 bytes into a destination of size16
         snprintf(qname, sizeof(qname), "pickup%d", thread+1);
         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Solved by reducing 'thread' to a uint16_t and limiting the max
thread count to 1024.

src/runmode-erf-file.c
src/runmode-pcap-file.c
src/util-runmodes.c

index a5354bb42255c40faffe82df729e9ef549e2892a..5002030976c0ee62d1f18a985a20075b1bde75ee 100644 (file)
@@ -118,7 +118,7 @@ int RunModeErfFileAutoFp(void)
     char qname[TM_QUEUE_NAME_MAX];
     uint16_t cpu = 0;
     char *queues = NULL;
-    int thread;
+    uint16_t thread;
 
     RunModeInitialize();
 
@@ -145,6 +145,8 @@ int RunModeErfFileAutoFp(void)
         thread_max = ncpus * threading_detect_ratio;
     if (thread_max < 1)
         thread_max = 1;
+    if (thread_max > 1024)
+        thread_max = 1024;
 
     queues = RunmodeAutoFpCreatePickupQueuesString(thread_max);
     if (queues == NULL) {
@@ -189,9 +191,9 @@ int RunModeErfFileAutoFp(void)
         exit(EXIT_FAILURE);
     }
 
-    for (thread = 0; thread < thread_max; thread++) {
-        snprintf(tname, sizeof(tname), "%s#%02d", thread_name_workers, thread+1);
-        snprintf(qname, sizeof(qname), "pickup%d", thread+1);
+    for (thread = 0; thread < (uint16_t)thread_max; thread++) {
+        snprintf(tname, sizeof(tname), "%s#%02u", thread_name_workers, thread+1);
+        snprintf(qname, sizeof(qname), "pickup%u", thread+1);
 
         SCLogDebug("tname %s, qname %s", tname, qname);
 
index 29de79dc8f6fde205a2ec9c27efb1b578543a198..ae5cb84c71e91fa25986ed942d52b63e5696f5b8 100644 (file)
@@ -151,7 +151,7 @@ int RunModeFilePcapAutoFp(void)
     char qname[TM_QUEUE_NAME_MAX];
     uint16_t cpu = 0;
     char *queues = NULL;
-    int thread;
+    uint16_t thread;
 
     RunModeInitialize();
 
@@ -180,6 +180,8 @@ int RunModeFilePcapAutoFp(void)
         thread_max = ncpus * threading_detect_ratio;
     if (thread_max < 1)
         thread_max = 1;
+    if (thread_max > 1024)
+        thread_max = 1024;
 
     queues = RunmodeAutoFpCreatePickupQueuesString(thread_max);
     if (queues == NULL) {
@@ -222,9 +224,9 @@ int RunModeFilePcapAutoFp(void)
         exit(EXIT_FAILURE);
     }
 
-    for (thread = 0; thread < thread_max; thread++) {
+    for (thread = 0; thread < (uint16_t)thread_max; thread++) {
         snprintf(tname, sizeof(tname), "%s#%02u", thread_name_workers, thread+1);
-        snprintf(qname, sizeof(qname), "pickup%d", thread+1);
+        snprintf(qname, sizeof(qname), "pickup%u", thread+1);
 
         SCLogDebug("tname %s, qname %s", tname, qname);
         SCLogDebug("Assigning %s affinity to cpu %u", tname, cpu);
index caaff71ec43c4dcdad8b2eff546bb20bd2c75161..90fe21d34ea87c98de3803c5a7555a5a2b759767 100644 (file)
@@ -95,7 +95,8 @@ int RunModeSetLiveCaptureAutoFp(ConfigIfaceParserFunc ConfigParser,
     char tname[TM_THREAD_NAME_MAX];
     char qname[TM_QUEUE_NAME_MAX];
     char *queues = NULL;
-    int thread = 0;
+    uint16_t thread = 0;
+
     /* Available cpus */
     uint16_t ncpus = UtilCpuGetNumProcessorsOnline();
     int nlive = LiveGetDeviceCount();
@@ -105,6 +106,8 @@ int RunModeSetLiveCaptureAutoFp(ConfigIfaceParserFunc ConfigParser,
         thread_max = ncpus * threading_detect_ratio;
     if (thread_max < 1)
         thread_max = 1;
+    if (thread_max > 1024)
+        thread_max = 1024;
 
     queues = RunmodeAutoFpCreatePickupQueuesString(thread_max);
     if (queues == NULL) {
@@ -224,9 +227,9 @@ int RunModeSetLiveCaptureAutoFp(ConfigIfaceParserFunc ConfigParser,
         }
     }
 
-    for (thread = 0; thread < thread_max; thread++) {
-        snprintf(tname, sizeof(tname), "%s#%02d", thread_name_workers, thread+1);
-        snprintf(qname, sizeof(qname), "pickup%d", thread+1);
+    for (thread = 0; thread < (uint16_t)thread_max; thread++) {
+        snprintf(tname, sizeof(tname), "%s#%02u", thread_name_workers, thread+1);
+        snprintf(qname, sizeof(qname), "pickup%u", thread+1);
 
         SCLogDebug("tname %s, qname %s", tname, qname);
 
@@ -429,7 +432,7 @@ int RunModeSetIPSAutoFp(ConfigIPSParserFunc ConfigParser,
     TmModule *tm_module ;
     const char *cur_queue = NULL;
     char *queues = NULL;
-    int thread;
+    uint16_t thread;
 
     /* Available cpus */
     uint16_t ncpus = UtilCpuGetNumProcessorsOnline();
@@ -441,6 +444,8 @@ int RunModeSetIPSAutoFp(ConfigIPSParserFunc ConfigParser,
         thread_max = ncpus * threading_detect_ratio;
     if (thread_max < 1)
         thread_max = 1;
+    if (thread_max > 1024)
+        thread_max = 1024;
 
     queues = RunmodeAutoFpCreatePickupQueuesString(thread_max);
     if (queues == NULL) {
@@ -488,9 +493,9 @@ int RunModeSetIPSAutoFp(ConfigIPSParserFunc ConfigParser,
         }
 
     }
-    for (thread = 0; thread < thread_max; thread++) {
-        snprintf(tname, sizeof(tname), "%s#%02d", thread_name_workers, thread+1);
-        snprintf(qname, sizeof(qname), "pickup%d", thread+1);
+    for (thread = 0; thread < (uint16_t)thread_max; thread++) {
+        snprintf(tname, sizeof(tname), "%s#%02u", thread_name_workers, thread+1);
+        snprintf(qname, sizeof(qname), "pickup%u", thread+1);
 
         SCLogDebug("tname %s, qname %s", tname, qname);