Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

radix: Don't leak memory when key can't be added #9281

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/app-layer-htp.c
Original file line number Diff line number Diff line change
Expand Up @@ -2606,15 +2606,15 @@ static void HTPConfigParseParameters(HTPCfgRec *cfg_prec, ConfNode *s,
if (strchr(pval->val, ':') != NULL) {
SCLogDebug("LIBHTP adding ipv6 server %s at %s: %p",
s->name, pval->val, cfg_prec->cfg);
if (SCRadixAddKeyIPV6String(pval->val, tree, cfg_prec) == NULL) {
if (!SCRadixAddKeyIPV6String(pval->val, tree, cfg_prec)) {
SCLogWarning("LIBHTP failed to "
"add ipv6 server %s, ignoring",
pval->val);
}
} else {
SCLogDebug("LIBHTP adding ipv4 server %s at %s: %p",
s->name, pval->val, cfg_prec->cfg);
if (SCRadixAddKeyIPV4String(pval->val, tree, cfg_prec) == NULL) {
if (!SCRadixAddKeyIPV4String(pval->val, tree, cfg_prec)) {
SCLogWarning("LIBHTP failed "
"to add ipv4 server %s, ignoring",
pval->val);
Expand Down
14 changes: 10 additions & 4 deletions src/defrag-config.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,19 @@ static void DefragPolicyAddHostInfo(char *host_ip_range, uint64_t timeout)

if (strchr(host_ip_range, ':') != NULL) {
SCLogDebug("adding ipv6 host %s", host_ip_range);
if (SCRadixAddKeyIPV6String(host_ip_range, defrag_tree, (void *)user_data) == NULL) {
SCLogWarning("failed to add ipv6 host %s", host_ip_range);
if (!SCRadixAddKeyIPV6String(host_ip_range, defrag_tree, (void *)user_data)) {
SCFree(user_data);
if (sc_errno != SC_EEXIST) {
SCLogWarning("failed to add ipv6 host %s", host_ip_range);
}
}
} else {
SCLogDebug("adding ipv4 host %s", host_ip_range);
if (SCRadixAddKeyIPV4String(host_ip_range, defrag_tree, (void *)user_data) == NULL) {
SCLogWarning("failed to add ipv4 host %s", host_ip_range);
if (!SCRadixAddKeyIPV4String(host_ip_range, defrag_tree, (void *)user_data)) {
SCFree(user_data);
if (sc_errno != SC_EEXIST) {
SCLogWarning("failed to add ipv4 host %s", host_ip_range);
}
}
}
}
Expand Down
14 changes: 9 additions & 5 deletions src/reputation.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
SC_ATOMIC_DECLARE(uint32_t, srep_eversion);
/** reputation version set to the host's reputation,
* this will be set to 1 before rep files are loaded,
* so hosts will always have a minial value of 1 */
* so hosts will always have a minimal value of 1 */
static uint32_t srep_version = 0;

static uint32_t SRepIncrVersion(void)
Expand Down Expand Up @@ -99,8 +99,10 @@ static void SRepCIDRAddNetblock(SRepCIDRTree *cidr_ctx, char *ip, int cat, uint8
}

SCLogDebug("adding ipv6 host %s", ip);
if (SCRadixAddKeyIPV6String(ip, cidr_ctx->srepIPV6_tree[cat], (void *)user_data) == NULL) {
SCLogWarning("failed to add ipv6 host %s", ip);
if (!SCRadixAddKeyIPV6String(ip, cidr_ctx->srepIPV6_tree[cat], (void *)user_data)) {
SCFree(user_data);
if (sc_errno != SC_EEXIST)
SCLogWarning("failed to add ipv6 host %s", ip);
}

} else {
Expand All @@ -114,8 +116,10 @@ static void SRepCIDRAddNetblock(SRepCIDRTree *cidr_ctx, char *ip, int cat, uint8
}

SCLogDebug("adding ipv4 host %s", ip);
if (SCRadixAddKeyIPV4String(ip, cidr_ctx->srepIPV4_tree[cat], (void *)user_data) == NULL) {
SCLogWarning("failed to add ipv4 host %s", ip);
if (!SCRadixAddKeyIPV4String(ip, cidr_ctx->srepIPV4_tree[cat], (void *)user_data)) {
SCFree(user_data);
if (sc_errno != SC_EEXIST)
SCLogWarning("failed to add ipv4 host %s", ip);
}
}
}
Expand Down
1 change: 1 addition & 0 deletions src/util-error.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ const char * SCErrorToString(SCError err)
CASE_CODE(SC_ENOMEM);
CASE_CODE(SC_EINVAL);
CASE_CODE(SC_ELIMIT);
CASE_CODE(SC_EEXIST);

CASE_CODE (SC_ERR_MAX);
}
Expand Down
1 change: 1 addition & 0 deletions src/util-error.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ typedef enum {
SC_ENOMEM,
SC_EINVAL,
SC_ELIMIT,
SC_EEXIST,

SC_ERR_MAX
} SCError;
Expand Down
Loading
Loading