[master] 25228a2 VCL regexp and regsub should treat a NULL argument as an empty string.

Poul-Henning Kamp phk at varnish-cache.org
Mon May 16 13:05:56 CEST 2011


commit 25228a235b50c2e3b224a08473954bc99cf1d365
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Mon May 16 11:05:15 2011 +0000

    VCL regexp and regsub should treat a NULL argument as an empty
    string.
    
    Fixes	#913

diff --git a/bin/varnishd/cache_vrt_re.c b/bin/varnishd/cache_vrt_re.c
index 97d657c..0ae09ae 100644
--- a/bin/varnishd/cache_vrt_re.c
+++ b/bin/varnishd/cache_vrt_re.c
@@ -70,7 +70,7 @@ VRT_re_match(const char *s, void *re)
 	int i;
 
 	if (s == NULL)
-		return (0);
+		s = "";
 	AN(re);
 	t = re;
 	i = VRE_exec(t, s, strlen(s), 0, 0, NULL, 0);
@@ -94,7 +94,7 @@ VRT_regsub(const struct sess *sp, int all, const char *str, void *re,
 
 	AN(re);
 	if (str == NULL)
-		return ("");
+		str = "";
 	t = re;
 	memset(ovector, 0, sizeof(ovector));
 	i = VRE_exec(t, str, strlen(str), 0, 0, ovector, 30);
diff --git a/bin/varnishtest/tests/r00913.vtc b/bin/varnishtest/tests/r00913.vtc
new file mode 100644
index 0000000..519436f
--- /dev/null
+++ b/bin/varnishtest/tests/r00913.vtc
@@ -0,0 +1,22 @@
+varnishtest "test regsub(NULL)"
+
+server s1 {
+	rxreq
+	expect req.url == "/bar"
+	txresp -body "foobar"
+} -start
+
+varnish v1 -vcl+backend {
+	sub vcl_fetch {
+		if (beresp.http.bar ~ "$") {
+			set beresp.http.foo = regsub(beresp.http.bar, "$", "XXX");
+		}
+	}
+} -start
+
+client c1 {
+	txreq  -url /bar
+	rxresp 
+	expect resp.http.content-length == 6
+	expect resp.http.foo == "XXX"
+} -run



More information about the varnish-commit mailing list