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.
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;
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;