]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
Add some missing checks of SCMalloc return.
authorEric Leblond <eric@regit.org>
Fri, 21 Sep 2012 13:24:17 +0000 (15:24 +0200)
committerEric Leblond <eric@regit.org>
Tue, 25 Sep 2012 14:24:38 +0000 (16:24 +0200)
src/detect-fileext.c
src/detect-filemagic.c
src/detect-filename.c
src/util-cuda-handlers.c
src/util-pool.c
src/util-profiling-rules.c
src/util-profiling.c
src/win32-misc.c

index 6d724b3429ac2effacb229d34080ee9ae61b0a62..520f60881caecec965b8e34c5ffd1803b8f8dc56 100644 (file)
@@ -156,9 +156,11 @@ static DetectFileextData *DetectFileextParse (char *str)
 #ifdef DEBUG
     if (SCLogDebugEnabled()) {
         char *ext = SCMalloc(fileext->len + 1);
-        memcpy(ext, fileext->ext, fileext->len);
-        ext[fileext->len] = '\0';
-        SCLogDebug("will look for fileext %s", ext);
+        if (ext != NULL) {
+            memcpy(ext, fileext->ext, fileext->len);
+            ext[fileext->len] = '\0';
+            SCLogDebug("will look for fileext %s", ext);
+        }
     }
 #endif
 
index 725a148e2bf17b20fa44517a56666a9355ef558d..ed2e78fa5359fa6e98312e6d8f675e64250faefa 100644 (file)
@@ -167,9 +167,11 @@ static int DetectFilemagicMatch (ThreadVars *t, DetectEngineThreadCtx *det_ctx,
 #ifdef DEBUG
             if (SCLogDebugEnabled()) {
                 char *name = SCMalloc(filemagic->len + 1);
-                memcpy(name, filemagic->name, filemagic->len);
-                name[filemagic->len] = '\0';
-                SCLogDebug("will look for filemagic %s", name);
+                if (name != NULL) {
+                    memcpy(name, filemagic->name, filemagic->len);
+                    name[filemagic->len] = '\0';
+                    SCLogDebug("will look for filemagic %s", name);
+                }
             }
 #endif
 
@@ -222,9 +224,11 @@ static DetectFilemagicData *DetectFilemagicParse (char *str)
 #ifdef DEBUG
     if (SCLogDebugEnabled()) {
         char *name = SCMalloc(filemagic->len + 1);
-        memcpy(name, filemagic->name, filemagic->len);
-        name[filemagic->len] = '\0';
-        SCLogDebug("will look for filemagic %s", name);
+        if (name != NULL) {
+            memcpy(name, filemagic->name, filemagic->len);
+            name[filemagic->len] = '\0';
+            SCLogDebug("will look for filemagic %s", name);
+        }
     }
 #endif
 
index 16275388ec96258199efe5a6eb3dcdb8032d9d39..2940f17c013328102dc1655e5fda9e3e93dbbce6 100644 (file)
@@ -109,9 +109,11 @@ static int DetectFilenameMatch (ThreadVars *t, DetectEngineThreadCtx *det_ctx,
 #ifdef DEBUG
         if (SCLogDebugEnabled()) {
             char *name = SCMalloc(filename->len + 1);
-            memcpy(name, filename->name, filename->len);
-            name[filename->len] = '\0';
-            SCLogDebug("will look for filename %s", name);
+            if (name != NULL) {
+                memcpy(name, filename->name, filename->len);
+                name[filename->len] = '\0';
+                SCLogDebug("will look for filename %s", name);
+            }
         }
 #endif
 
@@ -165,9 +167,11 @@ static DetectFilenameData *DetectFilenameParse (char *str)
 #ifdef DEBUG
     if (SCLogDebugEnabled()) {
         char *name = SCMalloc(filename->len + 1);
-        memcpy(name, filename->name, filename->len);
-        name[filename->len] = '\0';
-        SCLogDebug("will look for filename %s", name);
+        if (name != NULL) {
+            memcpy(name, filename->name, filename->len);
+            name[filename->len] = '\0';
+            SCLogDebug("will look for filename %s", name);
+        }
     }
 #endif
 
index 987692c2323c5b1452e64f5c46a64b3da200b0ae..e3403573845c66f8c91058f39f9ce19319885ce0 100644 (file)
@@ -470,6 +470,9 @@ int SCCudaHlGetCudaModule(CUmodule *p_module, const char *ptx_image, int handle)
     /* select the ptx image based on the compute capability supported by all
      * devices (i.e. the lowest) */
     char* image = SCMalloc(strlen(ptx_image)+15);
+    if (image == NULL) {
+        exit(EXIT_FAILURE);
+    }
     memset(image, 0x0, sizeof(image));
 
     int major = INT_MAX;
index 108d66f6f827b1b260d931ce1b38f31812971b43..581824f9d223a7bf63200eb4117f51b60c81f086 100644 (file)
@@ -116,9 +116,9 @@ Pool *PoolInit(uint32_t size, uint32_t prealloc_size, uint32_t elt_size,  void *
     uint32_t u32 = 0;
     if (size > 0) {
         PoolBucket *pb = SCCalloc(size, sizeof(PoolBucket));
-        p->pb_buffer = pb;
-        if (pb == NULL)
+        if (unlikely(pb == NULL))
             goto error;
+        p->pb_buffer = pb;
         memset(pb, 0, size * sizeof(PoolBucket));
         for (u32 = 0; u32 < size; u32++) {
             /* populate pool */
@@ -350,6 +350,8 @@ void PoolPrintSaturation(Pool *p) {
 
 void *PoolTestAlloc() {
     void *ptr = SCMalloc(10);
+    if (ptr == NULL)
+        return NULL;
     return ptr;
 }
 int PoolTestInitArg(void *data, void *allocdata) {
index fffbf5df09ac90025dd7cf98688a709ce56d480f..086db4af8718c65f275643083de865dcd9638905 100644 (file)
@@ -168,6 +168,10 @@ void SCProfilingRulesGlobalInit(void) {
                     log_dir = DEFAULT_LOG_DIR;
 
                 profiling_file_name = SCMalloc(PATH_MAX);
+                if (profiling_file_name == NULL) {
+                    SCLogError(SC_ERR_MEM_ALLOC, "can't duplicate file name");
+                    exit(EXIT_FAILURE);
+                }
                 snprintf(profiling_file_name, PATH_MAX, "%s/%s", log_dir, filename);
 
                 const char *v = ConfNodeLookupChildValue(conf, "append");
index 4eee57deab4c517907139196c6cf9153489540d5..ee54a5dd2ff2e1b1530d27341fc0825916e60e57 100644 (file)
@@ -141,6 +141,11 @@ SCProfilingInit(void)
                     log_dir = DEFAULT_LOG_DIR;
 
                 profiling_packets_file_name = SCMalloc(PATH_MAX);
+                if (profiling_packets_file_name == NULL) {
+                    SCLogError(SC_ERR_MEM_ALLOC, "can't duplicate file name");
+                    exit(EXIT_FAILURE);
+                }
+
                 snprintf(profiling_packets_file_name, PATH_MAX, "%s/%s", log_dir, filename);
 
                 const char *v = ConfNodeLookupChildValue(conf, "append");
@@ -215,6 +220,11 @@ SCProfilingInit(void)
                     log_dir = DEFAULT_LOG_DIR;
 
                 profiling_locks_file_name = SCMalloc(PATH_MAX);
+                if (profiling_locks_file_name == NULL) {
+                    SCLogError(SC_ERR_MEM_ALLOC, "can't duplicate file name");
+                    exit(EXIT_FAILURE);
+                }
+
                 snprintf(profiling_locks_file_name, PATH_MAX, "%s/%s", log_dir, filename);
 
                 const char *v = ConfNodeLookupChildValue(conf, "append");
index 09d3130d3b88d659d8ba0cec1b9e555cb4696d9e..83f86aa8b5b48f2b5e5281002d41c40838d5d94f 100644 (file)
@@ -33,6 +33,8 @@ void setenv(const char *name, const char *value, int overwrite)
 {
        if (overwrite || NULL == getenv(name)) {
                char *str = SCMalloc(strlen(name) + strlen(value) + 2);
+               if (str == NULL)
+                       return;
                snprintf(str, strlen(name) + strlen(value) + 1, "%s=%s", name, value);
                putenv(str);
                SCFree(str);
@@ -42,6 +44,8 @@ void setenv(const char *name, const char *value, int overwrite)
 void unsetenv(const char *name)
 {
        char *str = SCMalloc(strlen(name) + 2);
+       if (str == NULL)
+               return;
        snprintf(str, strlen(name) + 1, "%s=", name);
        putenv(str);
        SCFree(str);