Commit b05e49ce authored by Geoff Simmons's avatar Geoff Simmons

Copy the match subject into workspace if it's not already in workspace,

so that backref/namedref are guaranteed to return strings in workspace.
parent f1bb0147
...@@ -557,18 +557,32 @@ match(VRT_CTX, pcre2_code *code, VCL_STRING subject, VCL_INT len, ...@@ -557,18 +557,32 @@ match(VRT_CTX, pcre2_code *code, VCL_STRING subject, VCL_INT len,
uint32_t options, pcre2_match_data *mdata, pcre2_match_context *mctx, uint32_t options, pcre2_match_data *mdata, pcre2_match_context *mctx,
const char * restrict const context, const char * restrict const caller) const char * restrict const context, const char * restrict const caller)
{ {
PCRE2_SPTR safe_subject;
int ret; int ret;
uintptr_t snap; uintptr_t snap;
char *msg; char *msg;
if (subject == NULL) if (subject == NULL) {
subject = ""; safe_subject = (PCRE2_SPTR)"";
if (len == 0) len = 0;
len = PCRE2_ZERO_TERMINATED; }
else if (len == 0)
len = strlen(subject);
if (subject != NULL) {
if (WS_Inside(ctx->ws, subject, subject + len))
safe_subject = (PCRE2_SPTR)subject;
else if ((safe_subject = WS_Copy(ctx->ws,
(const void *) subject, len))
== NULL) {
VERRNOMEM(ctx, "in %s%s: copying subject to workspace",
context, caller);
return 0;
}
}
/* XXX param for start_offset */ /* XXX param for start_offset */
ret = pcre2_match(code, (PCRE2_SPTR)subject, (PCRE2_SIZE)len, 0, ret = pcre2_match(code, safe_subject, (PCRE2_SIZE)len, 0, options,
options, mdata, mctx); mdata, mctx);
if (ret == PCRE2_ERROR_NOMATCH) if (ret == PCRE2_ERROR_NOMATCH)
return 0; return 0;
assert(ret != PCRE2_ERROR_PARTIAL); /* XXX */ assert(ret != PCRE2_ERROR_PARTIAL); /* XXX */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment