Commit 5ef43bd5 authored by Geoff Simmons's avatar Geoff Simmons

backref() method and function always fail if the fallback is NULL,

for example if set from an unset header
parent 6271111b
......@@ -41,6 +41,11 @@ varnish v1 -vcl+backend {
set resp.http.foo0 = barbaz.backref(0, "error0");
set resp.http.foo1 = barbaz.backref(1, "error1");
set resp.http.foo2 = barbaz.backref(2, "error2");
# Even if a match succeeded, backref() fails if
# the fallback is undefined.
set resp.http.undeffallback
= barbaz.backref(0, resp.http.undef);
}
/* match fails */
if (barbaz.match(resp.http.barf)) {
......@@ -71,6 +76,9 @@ varnish v1 -vcl+backend {
set resp.http.never0 = never.backref(0, "fallback0");
set resp.http.never1 = never.backref(1, "fallback1");
set resp.http.never2 = never.backref(2, "fallback2");
/* Fallback default */
set resp.http.nofallback = never.backref(0);
}
} -start
......@@ -87,6 +95,7 @@ client c1 {
expect resp.http.foo0 == "barbaz"
expect resp.http.foo1 == "bar"
expect resp.http.foo2 == "baz"
expect resp.http.undeffallback ~ "^..BACKREF (METHOD|FUNCTION) FAILED..$"
expect resp.http.puke == <undef>
expect resp.http.barf0 == "fallback0"
expect resp.http.barf1 == "fallback1"
......@@ -99,6 +108,7 @@ client c1 {
expect resp.http.never0 == "fallback0"
expect resp.http.never1 == "fallback1"
expect resp.http.never2 == "fallback2"
expect resp.http.nofallback ~ "^..BACKREF (METHOD|FUNCTION) FAILED..$"
} -run
logexpect l1 -v v1 -d 1 -g vxid -q "VCL_Error" {
......@@ -111,6 +121,8 @@ logexpect l1 -v v1 -d 1 -g vxid -q "VCL_Error" {
# would have also failed due to failing prior match
expect * = VCL_Error "^vmod re2 error: frobnitz.backref.ref=3, fallback=.fallback3..: backref out of range .max 2.$"
expect * = VCL_Error "^vmod re2 error: barbaz.backref.ref=0, fallback=.<undefined>..: fallback is undefined$"
expect * = VCL_Error "^vmod re2 error: never.backref.ref=0, fallback=.fallback0..: never_capture is true for object never$"
expect * = VCL_Error "^vmod re2 error: never.backref.ref=1, fallback=.fallback1..: never_capture is true for object never$"
expect * = VCL_Error "^vmod re2 error: never.backref.ref=2, fallback=.fallback2..: never_capture is true for object never$"
......@@ -235,6 +247,8 @@ varnish v1 -vcl+backend {
set resp.http.foo0 = re2.backref(0, "error0");
set resp.http.foo1 = re2.backref(1, "error1");
set resp.http.foo2 = re2.backref(2, "error2");
set resp.http.undeffallback
= re2.backref(0, resp.http.undef);
}
if (re2.match("(bar)(baz)", resp.http.barf)) {
set resp.http.puke = "match";
......@@ -258,6 +272,8 @@ varnish v1 -vcl+backend {
set resp.http.never0 = re2.backref(0, "fallback0");
set resp.http.never1 = re2.backref(1, "fallback1");
set resp.http.never2 = re2.backref(2, "fallback2");
set resp.http.nofallback = re2.backref(0);
}
}
......@@ -265,6 +281,7 @@ logexpect l3 -v v1 -d 0 -g vxid -q "VCL_Error" {
expect 0 * Begin req
expect * = VCL_Error "^vmod re2 error: re2.backref.ref=0, fallback=.fallback..: called without previous match$"
expect * = VCL_Error "^vmod re2 error: re2.backref.ref=3, fallback=.fallback3..: backref out of range .max 2.$"
expect * = VCL_Error "^vmod re2 error: re2.backref.ref=0, fallback=.<undefined>..: fallback is undefined$"
expect * = VCL_Error "^vmod re2 error: re2.backref.ref=0, fallback=.fallback0..: never_capture was true in previous match$"
expect * = VCL_Error "^vmod re2 error: re2.backref.ref=1, fallback=.fallback1..: never_capture was true in previous match$"
expect * = VCL_Error "^vmod re2 error: re2.backref.ref=2, fallback=.fallback2..: never_capture was true in previous match$"
......
......@@ -362,8 +362,11 @@ vmod_regex_backref(VRT_CTX, struct vmod_re2_regex *re, VCL_INT refnum,
CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
CHECK_OBJ_NOTNULL(re, VMOD_RE2_REGEX_MAGIC);
assert(refnum >= 0);
if (fallback == NULL)
fallback = "";
if (fallback == NULL) {
VERR(ctx, ERR_PREFIX "fallback is undefined", re->vcl_name,
refnum, "<undefined>");
return "**BACKREF METHOD FAILED**";
}
if (re->never_capture) {
VERR(ctx, ERR_PREFIX "never_capture is true for object %s",
......@@ -643,8 +646,11 @@ vmod_backref(VRT_CTX, struct vmod_priv *priv, VCL_INT refnum,
CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
AN(priv);
assert(refnum >= 0);
if (fallback == NULL)
fallback = "";
if (fallback == NULL) {
VERR(ctx, ERR_PREFIX "fallback is undefined", refnum,
"<undefined>");
return "**BACKREF FUNCTION FAILED**";
}
if (priv->priv == NULL) {
VERR(ctx, ERR_PREFIX "called without previous match", refnum,
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