]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
Add some missing checks of SCStrdup return.
authorEric Leblond <eric@regit.org>
Fri, 21 Sep 2012 21:26:53 +0000 (23:26 +0200)
committerEric Leblond <eric@regit.org>
Tue, 25 Sep 2012 14:24:39 +0000 (16:24 +0200)
14 files changed:
src/conf.c
src/detect-engine-address.c
src/detect-engine-iponly.c
src/detect-engine-port.c
src/detect-id.c
src/detect-ssl-version.c
src/detect-tls-version.c
src/detect-tls.c
src/detect.c
src/runmode-erf-file.c
src/runmode-napatech.c
src/runmode-pcap-file.c
src/runmodes.c
src/util-runmodes.c

index 3f04723f40cfa51f17b6c3050aafbd67d488b096..dd11948a1e20fe21e46ba7d229f63815440c86a0 100644 (file)
@@ -129,6 +129,9 @@ ConfGetNode(char *key)
 
     /* Need to dup the key for tokenization... */
     char *tokstr = SCStrdup(key);
+    if (tokstr == NULL) {
+        return NULL;
+    }
 
 #if defined(__WIN32) || defined(_WIN32)
     token = strtok(tokstr, ".");
@@ -195,6 +198,9 @@ ConfSet(char *name, char *val, int allow_override)
     }
     else {
         char *tokstr = SCStrdup(name);
+        if (tokstr == NULL) {
+            return 0;
+        }
 #if defined(__WIN32) || defined(_WIN32)
         token = strtok(tokstr, ".");
 #else
@@ -727,9 +733,13 @@ char *ConfLoadCompleteIncludePath(char *file)
             strlcat(path, file, path_len);
        } else {
             path = SCStrdup(file);
+            if (path == NULL)
+                return NULL;
         }
     } else {
         path = SCStrdup(file);
+        if (path == NULL)
+            return NULL;
     }
     return path;
 }
index 8c120f32bf3d6ea9009cf84f6f9bf22a90b209f1..001fd7ba8527a7a8696ef735e1af70b3265c3ca1 100644 (file)
@@ -602,6 +602,8 @@ int DetectAddressParseString(DetectAddress *dd, char *str)
     char *mask = NULL;
     int r = 0;
 
+    if (ipdup == NULL)
+        return -1;
     SCLogDebug("str %s", str);
 
     /* first handle 'any' */
index 21cafc735ffe3fff339f6ff067e23972844b7191..355b2b4ef7ba0f55051ac8bfedd099f7d5e858a1 100644 (file)
@@ -108,6 +108,8 @@ static int IPOnlyCIDRItemParseSingle(IPOnlyCIDRItem *dd, char *str)
     char *mask = NULL;
     int r = 0;
 
+    if (ipdup == NULL)
+        return -1;
     SCLogDebug("str %s", str);
 
     /* first handle 'any' */
index b2420185606bd72d1a581baa7bc5a869c5d2ace2..afa7e88bdbb5cec9a8c26e146ae2429c30dbb469 100644 (file)
@@ -1383,6 +1383,9 @@ DetectPort *PortParse(char *str) {
     char *port2 = NULL;
     DetectPort *dp = NULL;
 
+    if (portdup == NULL) {
+        return NULL;
+    }
     dp = DetectPortInit();
     if (dp == NULL)
         goto error;
index 1627810f02ebe0318c89cad9f145608d175c008e..a7973b15fb884b29cfef61612fdb9f19bdc9e44b 100644 (file)
@@ -165,10 +165,10 @@ DetectIdData *DetectIdParse (char *idstr)
             goto error;
 
         orig = SCStrdup((char*)str_ptr);
-        tmp_str=orig;
-        if (tmp_str == NULL) {
+        if (orig == NULL) {
             goto error;
         }
+        tmp_str=orig;
 
         /* Let's see if we need to scape "'s */
         if (tmp_str[0] == '"')
index 292c345cfd472e6ad3b3590ec1c486feaa6d33cb..186769f5d3c0d9351c917fc8cba230dc8ec60460 100644 (file)
@@ -224,10 +224,10 @@ DetectSslVersionData *DetectSslVersionParse(char *str)
             }
 
             orig = SCStrdup((char*) str_ptr[i]);
-            tmp_str = orig;
-            if (tmp_str == NULL) {
+            if (orig == NULL) {
                 goto error;
             }
+            tmp_str = orig;
 
             /* Let's see if we need to scape "'s */
             if (tmp_str[0] == '"') {
index b356bfdeae22b51dcce922391535ae0e3041d716..f4435c3e9769078f423ef4167ed753bd763c06a7 100644 (file)
@@ -179,10 +179,10 @@ DetectTlsVersionData *DetectTlsVersionParse (char *str)
             goto error;
 
         orig = SCStrdup((char*)str_ptr);
-        tmp_str=orig;
-        if (tmp_str == NULL) {
+        if (orig == NULL) {
             goto error;
         }
+        tmp_str=orig;
 
         /* Let's see if we need to scape "'s */
         if (tmp_str[0] == '"')
index a54c5ba8cefc1acc9520bef512dd063e1d5e2a48..ae48b3607bb1b246bbfe851339013f534aa70c98 100644 (file)
@@ -284,10 +284,10 @@ static DetectTlsData *DetectTlsSubjectParse (char *str)
     tls->flags = flag;
 
     orig = SCStrdup((char*)str_ptr);
-    tmp_str=orig;
-    if (tmp_str == NULL) {
+    if (orig == NULL) {
         goto error;
     }
+    tmp_str=orig;
 
     /* Let's see if we need to escape "'s */
     if (tmp_str[0] == '"') {
@@ -483,10 +483,10 @@ static DetectTlsData *DetectTlsIssuerDNParse(char *str)
     tls->flags = flag;
 
     orig = SCStrdup((char*)str_ptr);
-    tmp_str=orig;
-    if (tmp_str == NULL) {
+    if (orig == NULL) {
         goto error;
     }
+    tmp_str=orig;
 
     /* Let's see if we need to escape "'s */
     if (tmp_str[0] == '"')
@@ -619,10 +619,10 @@ static DetectTlsData *DetectTlsFingerprintParse (char *str)
     tls->flags = flag;
 
     orig = SCStrdup((char*)str_ptr);
-    tmp_str=orig;
-    if (tmp_str == NULL) {
+    if (orig == NULL) {
         goto error;
     }
+    tmp_str=orig;
 
     /* Let's see if we need to escape "'s */
     if (tmp_str[0] == '"')
index f76f0b4db4a9e65cc5b8c82b12b2ce8033a8b3f6..0f64639731882f3126bc2a46686a4623d1575a93 100644 (file)
@@ -257,9 +257,13 @@ char *DetectLoadCompleteSigPath(char *sig_file)
             strlcat(path, sig_file, path_len);
        } else {
             path = SCStrdup(sig_file);
+            if (path == NULL)
+                return NULL;
         }
     } else {
         path = SCStrdup(sig_file);
+        if (path == NULL)
+            return NULL;
     }
     return path;
 }
index 3d11aefaf71b356979a17c50b1cc9c3f36405fe5..b514944757042aedcd060fe3fbd6e973a85e693a 100644 (file)
@@ -210,6 +210,10 @@ int RunModeErfFileAutoFp(DetectEngineCtx *de_ctx)
         SCLogDebug("tname %s, qname %s", tname, qname);
 
         char *thread_name = SCStrdup(tname);
+        if (thread_name == NULL) {
+            printf("ERROR: Can't allocate thread name\n");
+            exit(EXIT_FAILURE);
+        }
         SCLogDebug("Assigning %s affinity to cpu %u", thread_name, cpu);
 
         ThreadVars *tv_detect_ncpu =
index 170386f1d769b3c02dddb5e23b56f053e7172344..cbc11221ad6417f9ee5009e6a301fd0cfcd0b3bd 100644 (file)
@@ -95,12 +95,25 @@ int RunModeNapatechAuto(DetectEngineCtx *de_ctx) {
     for (feed=0; feed < feed_count; feed++) {
         snprintf(tname, sizeof(tname),"%"PRIu16":%"PRIu16, adapter, feed);
         feedName = SCStrdup(tname);
+        if (feedName == NULL) {
+            fprintf(stderr, "ERROR: Alloc feed name\n");
+            exit(EXIT_FAILURE);
+        }
 
         snprintf(tname, sizeof(tname),"Feed%"PRIu16,feed);
         threadName = SCStrdup(tname);
+        if (threadName == NULL) {
+            fprintf(stderr, "ERROR: Alloc thread name\n");
+            exit(EXIT_FAILURE);
+        }
+
 
         snprintf(tname, sizeof(tname),"feed-queue%"PRIu16,feed);
         outQueueName = SCStrdup(tname);
+        if (outQueueName == NULL) {
+            fprintf(stderr, "ERROR: Alloc output queue name\n");
+            exit(EXIT_FAILURE);
+        }
 
         /* create the threads */
         ThreadVars *tv_napatechFeed = TmThreadCreatePacketHandler(threadName,"packetpool",
@@ -149,8 +162,16 @@ int RunModeNapatechAuto(DetectEngineCtx *de_ctx) {
         {
             snprintf(tname, sizeof(tname),"Detect%"PRIu16"/%"PRIu16,feed,detect++);
             threadName = SCStrdup(tname);
+            if (threadName == NULL) {
+                fprintf(stderr, "ERROR: can not strdup thread name\n");
+                exit(EXIT_FAILURE);
+            }
             snprintf(tname, sizeof(tname),"feed-queue%"PRIu16,feed);
             inQueueName = SCStrdup(tname);
+            if (inQueueName == NULL) {
+                fprintf(stderr, "ERROR: can not strdup in queue name\n");
+                exit(EXIT_FAILURE);
+            }
 
             ThreadVars *tv_detect = TmThreadCreatePacketHandler(threadName,
                     inQueueName,"simple",
@@ -241,12 +262,24 @@ int RunModeNapatechAuto2(DetectEngineCtx *de_ctx) {
     for (feed=0; feed < feed_count; feed++) {
         snprintf(tname, sizeof(tname),"%"PRIu16":%"PRIu16, adapter, feed);
         feedName = SCStrdup(tname);
+        if (feedName == NULL) {
+            fprintf(stderr, "ERROR: can not strdup feed name\n");
+            exit(EXIT_FAILURE);
+        }
 
         snprintf(tname, sizeof(tname),"Feed%"PRIu16,feed);
         threadName = SCStrdup(tname);
+        if (threadName == NULL) {
+            fprintf(stderr, "ERROR: can not strdup in thread name\n");
+            exit(EXIT_FAILURE);
+        }
 
         snprintf(tname, sizeof(tname),"feed-queue%"PRIu16,feed);
         outQueueName = SCStrdup(tname);
+        if (outQueueName == NULL) {
+            fprintf(stderr, "ERROR: can not strdup out queue name\n");
+            exit(EXIT_FAILURE);
+        }
 
         /* create the threads */
         ThreadVars *tv_napatechFeed = TmThreadCreatePacketHandler(threadName,"packetpool",
index 4128b02e6c4960e2e11a513d97b56e1395c552d3..9829b8eee0bba907743299874b8bde0d07a92b04 100644 (file)
@@ -293,6 +293,10 @@ int RunModeFilePcapAuto(DetectEngineCtx *de_ctx)
         snprintf(tname, sizeof(tname), "Detect%"PRIu16, thread+1);
 
         char *thread_name = SCStrdup(tname);
+        if (thread_name == NULL) {
+            printf("ERROR: Can not strdup thread name\n");
+            exit(EXIT_FAILURE);
+        }
         SCLogDebug("Assigning %s affinity to cpu %u", thread_name, cpu);
 
         ThreadVars *tv_detect_ncpu =
@@ -456,6 +460,10 @@ int RunModeFilePcapAutoFp(DetectEngineCtx *de_ctx)
         SCLogDebug("tname %s, qname %s", tname, qname);
 
         char *thread_name = SCStrdup(tname);
+        if (thread_name == NULL) {
+            printf("ERROR: Can not strdup thread name\n");
+            exit(EXIT_FAILURE);
+        }
         SCLogDebug("Assigning %s affinity to cpu %u", thread_name, cpu);
 
         ThreadVars *tv_detect_ncpu =
index 9fab3ee78389ac8e3cdb55e6fb9c2eb4119fd516..4802eb8eba9b23d51a9353997efd7947bdfc6eb5 100644 (file)
@@ -276,6 +276,10 @@ void RunModeDispatch(int runmode, const char *custom_mode, DetectEngineCtx *de_c
             SCLogWarning(SC_ERR_RUNMODE, "'worker' mode have been renamed "
                          "to 'workers', please modify your setup.");
             custom_mode = SCStrdup("workers");
+            if (unlikely(custom_mode == NULL)) {
+                SCLogError(SC_ERR_MEM_ALLOC, "Unable to dup custom mode");
+                exit(EXIT_FAILURE);
+            }
         }
     }
 
@@ -290,6 +294,10 @@ void RunModeDispatch(int runmode, const char *custom_mode, DetectEngineCtx *de_c
 
     /* Export the custom mode */
     active_runmode = SCStrdup(custom_mode);
+    if (unlikely(active_runmode == NULL)) {
+        SCLogError(SC_ERR_MEM_ALLOC, "Unable to dup active mode");
+        exit(EXIT_FAILURE);
+    }
 
     mode->RunModeFunc(de_ctx);
 
index 6e37ad8603855ce038a78cc1f964fbaefef261aa..68ff4cb81d2c95dd15137355a748b44f4c2da9e7 100644 (file)
@@ -797,6 +797,10 @@ int RunModeSetIPSAuto(DetectEngineCtx *de_ctx,
         snprintf(tname, sizeof(tname), "Recv-Q%s", cur_queue);
 
         char *thread_name = SCStrdup(tname);
+        if (unlikely(thread_name == NULL)) {
+            printf("ERROR: Can't create thread name failed\n");
+            exit(EXIT_FAILURE);
+        }
         ThreadVars *tv_receivenfq =
             TmThreadCreatePacketHandler(thread_name,
                                         "packetpool", "packetpool",
@@ -866,6 +870,10 @@ int RunModeSetIPSAuto(DetectEngineCtx *de_ctx,
         snprintf(tname, sizeof(tname), "Detect%"PRIu16, thread+1);
 
         char *thread_name = SCStrdup(tname);
+        if (unlikely(thread_name == NULL)) {
+            printf("ERROR: thead name creation failed\n");
+            exit(EXIT_FAILURE);
+        }
         SCLogDebug("Assigning %s affinity", thread_name);
 
         ThreadVars *tv_detect_ncpu =
@@ -906,6 +914,10 @@ int RunModeSetIPSAuto(DetectEngineCtx *de_ctx,
         snprintf(tname, sizeof(tname), "Verdict%"PRIu16, i);
 
         char *thread_name = SCStrdup(tname);
+        if (unlikely(thread_name == NULL)) {
+            printf("ERROR: thead name creation failed\n");
+            exit(EXIT_FAILURE);
+        }
         ThreadVars *tv_verdict =
             TmThreadCreatePacketHandler(thread_name,
                                         "verdict-queue", "simple",
@@ -1005,7 +1017,10 @@ int RunModeSetIPSAutoFp(DetectEngineCtx *de_ctx,
         snprintf(tname, sizeof(tname), "Recv-Q%s", cur_queue);
 
         char *thread_name = SCStrdup(tname);
-
+        if (unlikely(thread_name == NULL)) {
+            printf("ERROR: thead name creation failed\n");
+            exit(EXIT_FAILURE);
+        }
         ThreadVars *tv_receive =
             TmThreadCreatePacketHandler(thread_name,
                     "packetpool", "packetpool",
@@ -1094,6 +1109,10 @@ int RunModeSetIPSAutoFp(DetectEngineCtx *de_ctx,
         snprintf(tname, sizeof(tname), "Verdict%"PRIu16, i);
 
         char *thread_name = SCStrdup(tname);
+        if (unlikely(thread_name == NULL)) {
+            SCLogError(SC_ERR_RUNMODE, "Error allocating memory");
+            exit(EXIT_FAILURE);
+        }
         ThreadVars *tv_verdict =
             TmThreadCreatePacketHandler(thread_name,
                                         "verdict-queue", "simple",
@@ -1151,6 +1170,10 @@ int RunModeSetIPSWorker(DetectEngineCtx *de_ctx,
         snprintf(tname, sizeof(tname), "Worker-Q%s", cur_queue);
 
         char *thread_name = SCStrdup(tname);
+        if (unlikely(thread_name == NULL)) {
+            SCLogError(SC_ERR_RUNMODE, "Error allocating memory");
+            exit(EXIT_FAILURE);
+        }
         tv = TmThreadCreatePacketHandler(thread_name,
                 "packetpool", "packetpool",
                 "packetpool", "packetpool",