Add some missing checks of SCMalloc return.

pull/91/head
Eric Leblond 14 years ago
parent d8667448c1
commit 655577cbbc

@ -156,9 +156,11 @@ static DetectFileextData *DetectFileextParse (char *str)
#ifdef DEBUG #ifdef DEBUG
if (SCLogDebugEnabled()) { if (SCLogDebugEnabled()) {
char *ext = SCMalloc(fileext->len + 1); char *ext = SCMalloc(fileext->len + 1);
memcpy(ext, fileext->ext, fileext->len); if (ext != NULL) {
ext[fileext->len] = '\0'; memcpy(ext, fileext->ext, fileext->len);
SCLogDebug("will look for fileext %s", ext); ext[fileext->len] = '\0';
SCLogDebug("will look for fileext %s", ext);
}
} }
#endif #endif

@ -167,9 +167,11 @@ static int DetectFilemagicMatch (ThreadVars *t, DetectEngineThreadCtx *det_ctx,
#ifdef DEBUG #ifdef DEBUG
if (SCLogDebugEnabled()) { if (SCLogDebugEnabled()) {
char *name = SCMalloc(filemagic->len + 1); char *name = SCMalloc(filemagic->len + 1);
memcpy(name, filemagic->name, filemagic->len); if (name != NULL) {
name[filemagic->len] = '\0'; memcpy(name, filemagic->name, filemagic->len);
SCLogDebug("will look for filemagic %s", name); name[filemagic->len] = '\0';
SCLogDebug("will look for filemagic %s", name);
}
} }
#endif #endif
@ -222,9 +224,11 @@ static DetectFilemagicData *DetectFilemagicParse (char *str)
#ifdef DEBUG #ifdef DEBUG
if (SCLogDebugEnabled()) { if (SCLogDebugEnabled()) {
char *name = SCMalloc(filemagic->len + 1); char *name = SCMalloc(filemagic->len + 1);
memcpy(name, filemagic->name, filemagic->len); if (name != NULL) {
name[filemagic->len] = '\0'; memcpy(name, filemagic->name, filemagic->len);
SCLogDebug("will look for filemagic %s", name); name[filemagic->len] = '\0';
SCLogDebug("will look for filemagic %s", name);
}
} }
#endif #endif

@ -109,9 +109,11 @@ static int DetectFilenameMatch (ThreadVars *t, DetectEngineThreadCtx *det_ctx,
#ifdef DEBUG #ifdef DEBUG
if (SCLogDebugEnabled()) { if (SCLogDebugEnabled()) {
char *name = SCMalloc(filename->len + 1); char *name = SCMalloc(filename->len + 1);
memcpy(name, filename->name, filename->len); if (name != NULL) {
name[filename->len] = '\0'; memcpy(name, filename->name, filename->len);
SCLogDebug("will look for filename %s", name); name[filename->len] = '\0';
SCLogDebug("will look for filename %s", name);
}
} }
#endif #endif
@ -165,9 +167,11 @@ static DetectFilenameData *DetectFilenameParse (char *str)
#ifdef DEBUG #ifdef DEBUG
if (SCLogDebugEnabled()) { if (SCLogDebugEnabled()) {
char *name = SCMalloc(filename->len + 1); char *name = SCMalloc(filename->len + 1);
memcpy(name, filename->name, filename->len); if (name != NULL) {
name[filename->len] = '\0'; memcpy(name, filename->name, filename->len);
SCLogDebug("will look for filename %s", name); name[filename->len] = '\0';
SCLogDebug("will look for filename %s", name);
}
} }
#endif #endif

@ -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 /* select the ptx image based on the compute capability supported by all
* devices (i.e. the lowest) */ * devices (i.e. the lowest) */
char* image = SCMalloc(strlen(ptx_image)+15); char* image = SCMalloc(strlen(ptx_image)+15);
if (image == NULL) {
exit(EXIT_FAILURE);
}
memset(image, 0x0, sizeof(image)); memset(image, 0x0, sizeof(image));
int major = INT_MAX; int major = INT_MAX;

@ -116,9 +116,9 @@ Pool *PoolInit(uint32_t size, uint32_t prealloc_size, uint32_t elt_size, void *
uint32_t u32 = 0; uint32_t u32 = 0;
if (size > 0) { if (size > 0) {
PoolBucket *pb = SCCalloc(size, sizeof(PoolBucket)); PoolBucket *pb = SCCalloc(size, sizeof(PoolBucket));
p->pb_buffer = pb; if (unlikely(pb == NULL))
if (pb == NULL)
goto error; goto error;
p->pb_buffer = pb;
memset(pb, 0, size * sizeof(PoolBucket)); memset(pb, 0, size * sizeof(PoolBucket));
for (u32 = 0; u32 < size; u32++) { for (u32 = 0; u32 < size; u32++) {
/* populate pool */ /* populate pool */
@ -350,6 +350,8 @@ void PoolPrintSaturation(Pool *p) {
void *PoolTestAlloc() { void *PoolTestAlloc() {
void *ptr = SCMalloc(10); void *ptr = SCMalloc(10);
if (ptr == NULL)
return NULL;
return ptr; return ptr;
} }
int PoolTestInitArg(void *data, void *allocdata) { int PoolTestInitArg(void *data, void *allocdata) {

@ -168,6 +168,10 @@ void SCProfilingRulesGlobalInit(void) {
log_dir = DEFAULT_LOG_DIR; log_dir = DEFAULT_LOG_DIR;
profiling_file_name = SCMalloc(PATH_MAX); 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); snprintf(profiling_file_name, PATH_MAX, "%s/%s", log_dir, filename);
const char *v = ConfNodeLookupChildValue(conf, "append"); const char *v = ConfNodeLookupChildValue(conf, "append");

@ -141,6 +141,11 @@ SCProfilingInit(void)
log_dir = DEFAULT_LOG_DIR; log_dir = DEFAULT_LOG_DIR;
profiling_packets_file_name = SCMalloc(PATH_MAX); 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); snprintf(profiling_packets_file_name, PATH_MAX, "%s/%s", log_dir, filename);
const char *v = ConfNodeLookupChildValue(conf, "append"); const char *v = ConfNodeLookupChildValue(conf, "append");
@ -215,6 +220,11 @@ SCProfilingInit(void)
log_dir = DEFAULT_LOG_DIR; log_dir = DEFAULT_LOG_DIR;
profiling_locks_file_name = SCMalloc(PATH_MAX); 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); snprintf(profiling_locks_file_name, PATH_MAX, "%s/%s", log_dir, filename);
const char *v = ConfNodeLookupChildValue(conf, "append"); const char *v = ConfNodeLookupChildValue(conf, "append");

@ -33,6 +33,8 @@ void setenv(const char *name, const char *value, int overwrite)
{ {
if (overwrite || NULL == getenv(name)) { if (overwrite || NULL == getenv(name)) {
char *str = SCMalloc(strlen(name) + strlen(value) + 2); char *str = SCMalloc(strlen(name) + strlen(value) + 2);
if (str == NULL)
return;
snprintf(str, strlen(name) + strlen(value) + 1, "%s=%s", name, value); snprintf(str, strlen(name) + strlen(value) + 1, "%s=%s", name, value);
putenv(str); putenv(str);
SCFree(str); SCFree(str);
@ -42,6 +44,8 @@ void setenv(const char *name, const char *value, int overwrite)
void unsetenv(const char *name) void unsetenv(const char *name)
{ {
char *str = SCMalloc(strlen(name) + 2); char *str = SCMalloc(strlen(name) + 2);
if (str == NULL)
return;
snprintf(str, strlen(name) + 1, "%s=", name); snprintf(str, strlen(name) + 1, "%s=", name);
putenv(str); putenv(str);
SCFree(str); SCFree(str);

Loading…
Cancel
Save