Commit 4de7fa5a authored by Geoff Simmons's avatar Geoff Simmons

function match() fails if the regex is NULL

parent 5ef43bd5
# looks like -*- vcl -*-
varnishtest "regexp match and no-match (cf. varnish b00028.vtc)"
varnishtest "regexp match and no-match"
server s1 {
rxreq
txresp -hdr "Foo: bar" -hdr "Bar: foo" -body "1111\n"
} -start
# cf. varnish b00028.vtc
varnish v1 -vcl+backend {
import re2 from "${vmod_topbuild}/src/.libs/libvmod_re2.so";
......@@ -68,3 +69,31 @@ client c1 {
expect resp.http.foo1s == "1"
expect resp.http.bar1s == "2"
} -run
varnish v1 -vcl {
import re2 from "${vmod_topbuild}/src/.libs/libvmod_re2.so";
backend b { .host = "${bad_ip}"; }
sub vcl_recv {
return(synth(200));
}
sub vcl_synth {
if (re2.match(req.http.undef, "")) {
set resp.http.undef = "match";
}
}
}
client c2 {
txreq
rxresp
expect resp.status == "200"
expect resp.http.undef == <undef>
} -run
logexpect l1 -v v1 -d 1 -g vxid -q "VCL_Error" {
expect 0 * Begin req
expect * = VCL_Error "^vmod re2 error: re2.match.pattern=.<undefined>., text=...: pattern is undefined$"
expect * = End
} -run
......@@ -596,8 +596,13 @@ vmod_match(VRT_CTX, struct vmod_priv *priv, VCL_STRING pattern,
int ngroups = 0;
CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
if (pattern == NULL)
pattern = "";
if (subject == NULL)
subject = "";
if (pattern == NULL) {
VERR(ctx, ERR_PREFIX "pattern is undefined", "<undefined>",
subject);
return 0;
}
if ((err = vre2_init(&vre2, pattern, utf8, posix_syntax, longest_match,
max_mem, literal, never_nl, dot_nl, never_capture,
......
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