Skip to content

fix: replace strdup(error) with nginx pool allocation in config handlers#382

Open
eilandert wants to merge 3 commits into
owasp-modsecurity:masterfrom
eilandert:fix/strdup-config-error-leaks
Open

fix: replace strdup(error) with nginx pool allocation in config handlers#382
eilandert wants to merge 3 commits into
owasp-modsecurity:masterfrom
eilandert:fix/strdup-config-error-leaks

Conversation

@eilandert
Copy link
Copy Markdown

In ngx_conf_set_rules, ngx_conf_set_rules_file, and ngx_conf_set_rules_remote, rule load errors returned a strdup()- allocated string. Nginx treats the returned char* as a constant string and never frees it, causing a heap leak on every failed nginx -s reload when rule files have errors.

Replace with ngx_pstrdup(cf->pool, ...) so the error string is allocated from the config pool and freed automatically when nginx reloads configuration.

eilandert added 3 commits May 13, 2026 14:09
In ngx_conf_set_rules, ngx_conf_set_rules_file, and
ngx_conf_set_rules_remote, rule load errors returned a strdup()-
allocated string. Nginx treats the returned char* as a constant string
and never frees it, causing a heap leak on every failed nginx -s reload
when rule files have errors.

Replace with ngx_pstrdup(cf->pool, ...) so the error string is
allocated from the config pool and freed automatically when nginx
reloads configuration.

Severity: High
Reported-by: Security audit 2026-05-13
ngx_pstrdup returns u_char* but the config handler return type is char*.
nginx builds with -Werror=pointer-sign so this produced a compile error.
Add explicit (char*) cast at all three call sites.
@sonarqubecloud
Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant