diff --git a/qa/coccinelle/malloc-error-check.cocci b/qa/coccinelle/malloc-error-check.cocci index ce4d0cc47f96..d7d1bae8cf5b 100644 --- a/qa/coccinelle/malloc-error-check.cocci +++ b/qa/coccinelle/malloc-error-check.cocci @@ -1,7 +1,7 @@ @malloced@ expression x; position p1; -identifier func =~ "(SCMalloc|SCStrdup|SCCalloc|SCMallocAligned|SCRealloc)"; +identifier func =~ "SCMalloc\|SCStrdup\|SCCalloc\|SCMallocAligned\|SCRealloc"; @@ x@p1 = func(...) @@ -10,7 +10,7 @@ x@p1 = func(...) expression x, E; statement S; position malloced.p1; -identifier func =~ "(SCMalloc|SCStrdup|SCCalloc|SCMallocAligned|SCRealloc)"; +identifier func =~ "SCMalloc\|SCStrdup\|SCCalloc\|SCMallocAligned\|SCRealloc"; @@ ( @@ -22,7 +22,7 @@ if (E && (x@p1 = func(...)) == NULL) S @realloc exists@ position malloced.p1; expression x, E1; -identifier func =~ "(SCMalloc|SCCalloc|SCMallocAligned)"; +identifier func =~ "SCMalloc\|SCCalloc\|SCMallocAligned"; @@ x@p1 = func(...) @@ -33,7 +33,7 @@ x = SCRealloc(x, E1) expression x, E1; position malloced.p1; statement S1, S2; -identifier func =~ "(SCMalloc|SCStrdup|SCCalloc|SCMallocAligned|SCRealloc)"; +identifier func =~ "SCMalloc\|SCStrdup\|SCCalloc\|SCMallocAligned\|SCRealloc"; @@ x@p1 = func(...) diff --git a/src/decode.c b/src/decode.c index 6dd6701bfb0c..69a0163059fa 100644 --- a/src/decode.c +++ b/src/decode.c @@ -144,7 +144,9 @@ ExceptionPolicyStatsSetts flow_memcap_eps_stats = { PacketAlert *PacketAlertCreate(void) { PacketAlert *pa_array = SCCalloc(packet_alert_max, sizeof(PacketAlert)); - DEBUG_VALIDATE_BUG_ON(pa_array == NULL); + if (unlikely(pa_array == NULL)) { + FatalError("Failed to allocate packet alert array"); + } return pa_array; } diff --git a/src/detect-engine-alert.c b/src/detect-engine-alert.c index 1dcc78f4c86b..335c546306a2 100644 --- a/src/detect-engine-alert.c +++ b/src/detect-engine-alert.c @@ -337,6 +337,9 @@ static inline int PacketAlertSetContext( } } current_json->json_string = SCStrdup(det_ctx->json_content[i].json_content); + if (current_json->json_string == NULL) { + return -1; + } SCLogDebug("json content %u, value '%s' (%p)", (unsigned int)i, current_json->json_string, s); } diff --git a/src/detect-flowbits.c b/src/detect-flowbits.c index 438a2915f216..f443b510d541 100644 --- a/src/detect-flowbits.c +++ b/src/detect-flowbits.c @@ -791,11 +791,11 @@ int DetectFlowbitsAnalyze(DetectEngineCtx *de_ctx) uint32_t new_fb_array_size = s->init_data->rule_state_flowbits_ids_size + 1; void *tmp_fb_ptr = SCRealloc(s->init_data->rule_state_flowbits_ids_array, new_fb_array_size * sizeof(uint32_t)); - s->init_data->rule_state_flowbits_ids_array = tmp_fb_ptr; - if (s->init_data->rule_state_flowbits_ids_array == NULL) { + if (tmp_fb_ptr == NULL) { SCLogError("Failed to reallocate memory for rule_state_variable_idx"); goto error; } + s->init_data->rule_state_flowbits_ids_array = tmp_fb_ptr; SCLogDebug( "realloc'ed array for flowbits ids, new size is %u", new_fb_array_size); s->init_data->rule_state_dependant_sids_size = new_array_size; diff --git a/src/detect-reference.c b/src/detect-reference.c index 2981f3e5b68c..700d149c8c21 100644 --- a/src/detect-reference.c +++ b/src/detect-reference.c @@ -153,6 +153,9 @@ static DetectReference *DetectReferenceParse(const char *rawstr, DetectEngineCtx if (strlen(scheme)) { SCLogConfig("scheme value %s overrides key %s", scheme, key); ref->key = SCStrdup(scheme); + if (ref->key == NULL) { + goto error; + } /* already bound checked to be REFERENCE_SYSTEM_NAME_MAX or less */ ref->key_len = (uint16_t)strlen(scheme); } else { @@ -160,6 +163,9 @@ static DetectReference *DetectReferenceParse(const char *rawstr, DetectEngineCtx SCRConfReference *lookup_ref_conf = SCRConfGetReference(key, de_ctx); if (lookup_ref_conf != NULL) { ref->key = SCStrdup(lookup_ref_conf->url); + if (ref->key == NULL) { + goto error; + } /* already bound checked to be REFERENCE_SYSTEM_NAME_MAX or less */ ref->key_len = (uint16_t)strlen(ref->key); } else { diff --git a/src/util-log-redis.c b/src/util-log-redis.c index f0755e7473eb..adc6b23f7e59 100644 --- a/src/util-log-redis.c +++ b/src/util-log-redis.c @@ -673,6 +673,9 @@ int SCConfLogOpenRedis(SCConfNode *redis_node, void *lf_ctx) format string, whose length is limited by the length of the maxlen integer formatted as a string */ log_ctx->redis_setup.stream_format = SCCalloc(100, sizeof(char)); + if (unlikely(log_ctx->redis_setup.stream_format == NULL)) { + FatalError("Unable to allocate redis stream format"); + } snprintf(log_ctx->redis_setup.stream_format, 100, redis_stream_format_maxlen_tmpl, "%s", "%s", exact ? '=' : '~', maxlen, "%s"); log_ctx->redis_setup.format = log_ctx->redis_setup.stream_format; diff --git a/src/util-mpm-hs.c b/src/util-mpm-hs.c index 2d4daba19992..2a0b7d9675d0 100644 --- a/src/util-mpm-hs.c +++ b/src/util-mpm-hs.c @@ -641,7 +641,7 @@ static int CompileDataExtensionsInit(hs_expr_ext_t **ext, const SCHSPattern *p) { if (p->flags & (MPM_PATTERN_FLAG_OFFSET | MPM_PATTERN_FLAG_DEPTH)) { *ext = SCCalloc(1, sizeof(hs_expr_ext_t)); - if ((*ext) == NULL) { + if (*ext == NULL) { return -1; } if (p->flags & MPM_PATTERN_FLAG_OFFSET) { @@ -1179,6 +1179,9 @@ void SCHSPrintInfo(MpmCtx *mpm_ctx) static MpmConfig *SCHSConfigInit(void) { MpmConfig *c = SCCalloc(1, sizeof(MpmConfig)); + if (unlikely(c == NULL)) { + FatalError("Failed to allocate MpmConfig"); + } return c; }