Map: fixed regex pattern lifetime
Some checks failed
buildbot / buildbot (push) Has been cancelled

The regex pattern was referenced from the temporary pool used for
map block parsing, which is destroyed once the block is parsed.  The
pattern is later used for logging if regex matching fails, e.g., due
to PCRE2 match limit, JIT stack limit, or invalid UTF-8 with (*UTF),
resulting in released memory being logged.

The fix is to copy the pattern into the configuration pool.
This commit is contained in:
Roman Arutyunyan 2026-11-06 15:47:47 +04:00 • committed by Sergey Kandaurov
parent 62f94cf696
commit d17f1d249d
2 changed files with 16 additions and 2 deletions

View file

@ -547,7 +547,14 @@ found:
rc.options = NGX_REGEX_CASELESS;
}
rc.pattern = value[0];
rc.pattern.len = value[0].len;
rc.pattern.data = ngx_pnalloc(ctx->keys.pool, value[0].len + 1);
if (rc.pattern.data == NULL) {
return NGX_CONF_ERROR;
}
ngx_memcpy(rc.pattern.data, value[0].data, value[0].len + 1);
rc.err.len = NGX_MAX_CONF_ERRSTR;
rc.err.data = errstr;

View file

@ -546,7 +546,14 @@ found:
rc.options = NGX_REGEX_CASELESS;
}
rc.pattern = value[0];
rc.pattern.len = value[0].len;
rc.pattern.data = ngx_pnalloc(ctx->keys.pool, value[0].len + 1);
if (rc.pattern.data == NULL) {
return NGX_CONF_ERROR;
}
ngx_memcpy(rc.pattern.data, value[0].data, value[0].len + 1);
rc.err.len = NGX_MAX_CONF_ERRSTR;
rc.err.data = errstr;