Commit 703c622f authored by Geoff Simmons's avatar Geoff Simmons

Bugfix detecting if match() was not called before backref()

parent 09ccf296
......@@ -54,3 +54,43 @@ client c1 -repeat 2 {
expect resp.http.baz2 == "quux"
expect resp.http.frap == "_barf_frap_"
} -run
# backref failure
varnish v1 -vcl {
import pcre2 from "${vmod_topbuild}/src/.libs/libvmod_pcre2.so";
backend b { .host = "${bad_ip}"; }
sub vcl_init {
new frobnitz = pcre2.regex("(frob)(nitz)");
new barbaz = pcre2.regex("(bar)(baz)");
new azbc = pcre2.regex("(a|(z))(bc)");
}
sub vcl_recv {
return(synth(200));
}
sub vcl_synth {
# Call to backref() before match()
set resp.http.nomatch = barbaz.backref(0, "fallback");
# match() and backref() now re-use the object's task scope
if (barbaz.match("barbaz")) {
set resp.http.bar0 = barbaz.backref(0, "error0");
}
}
}
client c1 -repeat 2 {
txreq
rxresp
expect resp.status == "200"
expect resp.http.nomatch == "fallback"
expect resp.http.bar0 == "barbaz"
} -run
logexpect l1 -v v1 -d 1 -g vxid -q "VCL_Error" {
expect 0 * Begin req
expect * = VCL_Error "^vmod pcre2 error: barbaz.backref.0. called without prior match$"
expect * = End
} -run
......@@ -536,7 +536,8 @@ vmod_regex_backref(VRT_CTX, struct vmod_pcre2_regex *regex, VCL_INT ref,
CHECK_UINT32_RANGE(ref, regex->vcl_name, ".backref()", fallback);
match_task = VRT_priv_task(ctx, regex);
if (match_task == NULL) {
AN(match_task);
if (match_task->priv == NULL) {
VERR(ctx, "%s.backref(%ld) called without prior match",
regex->vcl_name, ref);
return fallback;
......
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