VarNameStoreRegister can return 0 in case of any error conditions.
Handle this case in all the users of this function. It is an unlikely
event so add branch assistance accordingly.
Bug 8054
if (unlikely(cd->or_list == NULL))
return -1;
for (uint8_t j = 0; j < cd->or_list_size ; j++) {
- cd->or_list[j] = VarNameStoreRegister(strarr[j], VAR_TYPE_FLOW_BIT);
+ uint32_t varname_id = VarNameStoreRegister(strarr[j], VAR_TYPE_FLOW_BIT);
+ if (unlikely(varname_id == 0))
+ return -1;
+ cd->or_list[j] = varname_id;
de_ctx->max_fb_id = MAX(cd->or_list[j], de_ctx->max_fb_id);
}
}
cd->cmd = fb_cmd;
} else {
- cd->idx = VarNameStoreRegister(fb_name, VAR_TYPE_FLOW_BIT);
+ uint32_t varname_id = VarNameStoreRegister(fb_name, VAR_TYPE_FLOW_BIT);
+ if (unlikely(varname_id == 0))
+ goto error;
+ cd->idx = varname_id;
de_ctx->max_fb_id = MAX(cd->idx, de_ctx->max_fb_id);
cd->cmd = fb_cmd;
cd->or_list_size = 0;
FAIL_IF_NULL(s);
idx = VarNameStoreRegister("myflow", VAR_TYPE_FLOW_BIT);
+ FAIL_IF_NOT(idx);
SigGroupBuild(de_ctx);
DetectEngineThreadCtxInit(&th_v, (void *)de_ctx, (void *)&det_ctx);
FAIL_IF_NULL(s);
idx = VarNameStoreRegister("myflow", VAR_TYPE_FLOW_BIT);
+ FAIL_IF_NOT(idx);
SigGroupBuild(de_ctx);
DetectEngineThreadCtxInit(&th_v, (void *)de_ctx, (void *)&det_ctx);
FAIL_IF_NULL(s);
idx = VarNameStoreRegister("myflow", VAR_TYPE_FLOW_BIT);
+ FAIL_IF_NOT(idx);
SigGroupBuild(de_ctx);
DetectEngineThreadCtxInit(&th_v, (void *)de_ctx, (void *)&det_ctx);
SCLogError("malloc from strdup failed");
goto error;
}
- sfd->idx = VarNameStoreRegister(varname, VAR_TYPE_FLOW_INT);
+ uint32_t varname_id = VarNameStoreRegister(varname, VAR_TYPE_FLOW_INT);
+ if (unlikely(varname_id == 0))
+ goto error;
+ sfd->idx = varname_id;
SCLogDebug("sfd->name %s id %u", sfd->name, sfd->idx);
sfd->modifier = modifier;
-/* Copyright (C) 2007-2020 Open Information Security Foundation
+/* Copyright (C) 2007-2025 Open Information Security Foundation
*
* You can copy, redistribute or modify this Program under the terms of
* the GNU General Public License version 2 as published by the Free
fd->name = SCStrdup(varname);
if (unlikely(fd->name == NULL))
goto error;
- fd->idx = VarNameStoreRegister(varname, VAR_TYPE_FLOW_VAR);
+ uint32_t varname_id = VarNameStoreRegister(varname, VAR_TYPE_FLOW_VAR);
+ if (unlikely(varname_id == 0))
+ goto error;
+ fd->idx = varname_id;
/* Okay so far so good, lets get this into a SigMatch
* and put it in the Signature. */
if (unlikely(cd == NULL))
goto error;
- cd->idx = VarNameStoreRegister(fb_name, VAR_TYPE_HOST_BIT);
+ uint32_t varname_id = VarNameStoreRegister(fb_name, VAR_TYPE_HOST_BIT);
+ if (unlikely(varname_id == 0))
+ goto error;
+ cd->idx = varname_id;
cd->cmd = fb_cmd;
cd->tracker = hb_dir;
cd->type = VAR_TYPE_HOST_BIT;
-/* Copyright (C) 2007-2024 Open Information Security Foundation
+/* Copyright (C) 2007-2025 Open Information Security Foundation
*
* You can copy, redistribute or modify this Program under the terms of
* the GNU General Public License version 2 as published by the Free
}
uint32_t idx = VarNameStoreRegister(value, VAR_TYPE_FLOW_VAR);
+ if (unlikely(idx == 0))
+ goto error;
ld->flowvar[ld->flowvars++] = idx;
SCLogDebug("script uses flowvar %u with script id %u", idx, ld->flowvars - 1);
}
}
uint32_t idx = VarNameStoreRegister(value, VAR_TYPE_FLOW_INT);
+ if (unlikely(idx == 0))
+ goto error;
ld->flowint[ld->flowints++] = idx;
SCLogDebug("script uses flowint %u with script id %u", idx, ld->flowints - 1);
}
return -1;
} else if (strncmp(name_array[name_idx], "flow:", 5) == 0) {
- pd->capids[pd->idx] =
+ uint32_t varname_id =
VarNameStoreRegister(name_array[name_idx] + 5, VAR_TYPE_FLOW_VAR);
+ if (unlikely(varname_id == 0))
+ return -1;
+ pd->capids[pd->idx] = varname_id;
pd->captypes[pd->idx] = VAR_TYPE_FLOW_VAR;
pd->idx++;
} else if (strncmp(name_array[name_idx], "pkt:", 4) == 0) {
- pd->capids[pd->idx] =
+ uint32_t varname_id =
VarNameStoreRegister(name_array[name_idx] + 4, VAR_TYPE_PKT_VAR);
+ if (unlikely(varname_id == 0))
+ return -1;
+ pd->capids[pd->idx] = varname_id;
pd->captypes[pd->idx] = VAR_TYPE_PKT_VAR;
SCLogDebug("id %u type %u", pd->capids[pd->idx], pd->captypes[pd->idx]);
pd->idx++;
} else if (strncmp(name_array[name_idx], "alert:", 6) == 0) {
- pd->capids[pd->idx] =
+ uint32_t varname_id =
VarNameStoreRegister(name_array[name_idx] + 6, VAR_TYPE_ALERT_VAR);
+ if (unlikely(varname_id == 0))
+ return -1;
+ pd->capids[pd->idx] = varname_id;
pd->captypes[pd->idx] = VAR_TYPE_ALERT_VAR;
pd->idx++;
}
if (strcmp(type_str, "pkt") == 0) {
- pd->capids[pd->idx] = VarNameStoreRegister((char *)capture_str, VAR_TYPE_PKT_VAR);
+ uint32_t varname_id = VarNameStoreRegister((char *)capture_str, VAR_TYPE_PKT_VAR);
+ if (unlikely(varname_id == 0))
+ return -1;
+ pd->capids[pd->idx] = varname_id;
pd->captypes[pd->idx] = VAR_TYPE_PKT_VAR;
SCLogDebug("id %u type %u", pd->capids[pd->idx], pd->captypes[pd->idx]);
pd->idx++;
} else if (strcmp(type_str, "flow") == 0) {
- pd->capids[pd->idx] = VarNameStoreRegister((char *)capture_str, VAR_TYPE_FLOW_VAR);
+ uint32_t varname_id = VarNameStoreRegister((char *)capture_str, VAR_TYPE_FLOW_VAR);
+ if (unlikely(varname_id == 0))
+ return -1;
+ pd->capids[pd->idx] = varname_id;
pd->captypes[pd->idx] = VAR_TYPE_FLOW_VAR;
pd->idx++;
} else if (strcmp(type_str, "alert") == 0) {
- pd->capids[pd->idx] = VarNameStoreRegister((char *)capture_str, VAR_TYPE_ALERT_VAR);
+ uint32_t varname_id = VarNameStoreRegister((char *)capture_str, VAR_TYPE_ALERT_VAR);
+ if (unlikely(varname_id == 0))
+ return -1;
+ pd->capids[pd->idx] = varname_id;
pd->captypes[pd->idx] = VAR_TYPE_ALERT_VAR;
pd->idx++;
}
size_t pcre2_len;
uint8_t *content = NULL;
uint16_t len = 0;
-
+ DetectPktvarData *cd = NULL;
pcre2_match_data *match = NULL;
int ret = DetectParsePcreExec(&parse_regex, &match, rawstr, 0, 0);
if (ret != 3) {
}
pcre2_substring_free((PCRE2_UCHAR8 *)varcontent);
- DetectPktvarData *cd = SCCalloc(1, sizeof(DetectPktvarData));
+ cd = SCCalloc(1, sizeof(DetectPktvarData));
if (unlikely(cd == NULL)) {
pcre2_substring_free((PCRE2_UCHAR8 *)varname);
SCFree(content);
cd->content = content;
cd->content_len = len;
- cd->id = VarNameStoreRegister(varname, VAR_TYPE_PKT_VAR);
+ uint32_t varname_id = VarNameStoreRegister(varname, VAR_TYPE_PKT_VAR);
+ if (unlikely(varname_id == 0))
+ goto error;
+ cd->id = varname_id;
pcre2_substring_free((PCRE2_UCHAR8 *)varname);
/* Okay so far so good, lets get this into a SigMatch
return 0;
error:
+ DetectPktvarFree(de_ctx, cd);
if (match) {
pcre2_match_data_free(match);
}
if (unlikely(cd == NULL))
return -1;
- cd->idx = VarNameStoreRegister(fb_name, var_type);
+ uint32_t varname_id = VarNameStoreRegister(fb_name, var_type);
+ if (unlikely(varname_id == 0))
+ goto error;
+ cd->idx = varname_id;
cd->cmd = fb_cmd;
cd->tracker = hb_dir;
cd->type = var_type;