]> err.no Git - varnish/commitdiff
Make regsub() return an empty string if it gets no input.
authorphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Fri, 20 Jun 2008 12:43:45 +0000 (12:43 +0000)
committerphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Fri, 20 Jun 2008 12:43:45 +0000 (12:43 +0000)
Fixes ticket 251 (regression test added)

git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@2743 d4fa192b-c00b-0410-8231-f00ffab90ce4

varnish-cache/bin/varnishd/cache_vrt_re.c
varnish-cache/bin/varnishtest/tests/r00251.vtc [new file with mode: 0644]

index 08de0b4498083e4216286bc089ba96bdfd32d872..2a8132ecb3a027d3e4c93be8a0caa9358aa6dc3a 100644 (file)
@@ -115,6 +115,8 @@ VRT_regsub(const struct sess *sp, int all, const char *str, void *re, const char
        unsigned u, x;
 
        AN(re);
+       if (str == NULL)
+               return ("");
        t = re;
        i = regexec(t, str, 10, pm, 0);
 
diff --git a/varnish-cache/bin/varnishtest/tests/r00251.vtc b/varnish-cache/bin/varnishtest/tests/r00251.vtc
new file mode 100644 (file)
index 0000000..86879b3
--- /dev/null
@@ -0,0 +1,33 @@
+# $Id$
+
+test "Regression test for #251: segfault on regsub on missing http header"
+
+server s1 {
+       rxreq 
+       txresp \
+               -hdr "Foobar: _barf_" \
+               -hdr "Connection: close" \
+               -body "012345\n"
+}
+
+varnish v1 -vcl+backend { 
+       sub vcl_fetch {
+               set obj.http.Snafu1 =
+                   "zoom"
+                   regsub(obj.http.Foomble, "ar", "\0\0")
+                   "box";
+       }
+} -start 
+
+server s1 -start 
+
+client c1 {
+       txreq -url "/"
+       rxresp
+       expect resp.status == 200
+       expect resp.http.X-Varnish == "1001"
+       expect resp.http.foobar == "_barf_"
+       expect resp.http.snafu1 == "zoombox"
+}
+
+client c1 -run