From dc46e3030e1f6be2471a1b102efe4d89785e42f5 Mon Sep 17 00:00:00 2001 From: phk Date: Fri, 20 Jun 2008 12:43:45 +0000 Subject: [PATCH] Make regsub() return an empty string if it gets no input. 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 | 2 ++ .../bin/varnishtest/tests/r00251.vtc | 33 +++++++++++++++++++ 2 files changed, 35 insertions(+) create mode 100644 varnish-cache/bin/varnishtest/tests/r00251.vtc diff --git a/varnish-cache/bin/varnishd/cache_vrt_re.c b/varnish-cache/bin/varnishd/cache_vrt_re.c index 08de0b44..2a8132ec 100644 --- a/varnish-cache/bin/varnishd/cache_vrt_re.c +++ b/varnish-cache/bin/varnishd/cache_vrt_re.c @@ -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 index 00000000..86879b30 --- /dev/null +++ b/varnish-cache/bin/varnishtest/tests/r00251.vtc @@ -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 -- 2.39.5