Conversation
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.
|
|
Confirming the problem this PR addresses: the Two points on the replacement:
libmodsecurity's own |



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.