From 9fa94dc340840a6d128d0fd80932221347171f7c Mon Sep 17 00:00:00 2001 From: phk Date: Fri, 19 Sep 2008 16:27:44 +0000 Subject: [PATCH] Don't crash if the backend sends only "HTTP/1.1 200" with no reason string. Fixes #325 git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@3203 d4fa192b-c00b-0410-8231-f00ffab90ce4 --- varnish-cache/bin/varnishd/cache_http.c | 13 ++++--- .../bin/varnishtest/tests/r00325.vtc | 37 +++++++++++++++++++ 2 files changed, 45 insertions(+), 5 deletions(-) create mode 100644 varnish-cache/bin/varnishtest/tests/r00325.vtc diff --git a/varnish-cache/bin/varnishd/cache_http.c b/varnish-cache/bin/varnishd/cache_http.c index a49d9fa2..18d50bb2 100644 --- a/varnish-cache/bin/varnishd/cache_http.c +++ b/varnish-cache/bin/varnishd/cache_http.c @@ -432,13 +432,15 @@ http_splitline(struct worker *w, int fd, struct http *hp, const struct http_conn for (; vct_issp(*p); p++) ; - /* Second field cannot contain SP, CRLF or CTL */ + /* Second field cannot contain LWS */ hp->hd[h2].b = p; - for (; !vct_issp(*p); p++) - if (vct_isctl(*p)) - return (400); + for (; !vct_islws(*p); p++) + ; hp->hd[h2].e = p; + if (!Tlen(hp->hd[h2])) + return (400); + /* Skip SP */ for (; vct_issp(*p); p++) ; @@ -520,7 +522,8 @@ http_DissectResponse(struct worker *w, const struct http_conn *htc, struct http hp->status = strtoul(hp->hd[HTTP_HDR_STATUS].b, NULL /* XXX */, 10); } - if (!Tlen(hp->hd[HTTP_HDR_RESPONSE])) { + if (hp->hd[HTTP_HDR_RESPONSE].b == NULL || + !Tlen(hp->hd[HTTP_HDR_RESPONSE])) { /* Backend didn't send a response string, use the standard */ hp->hd[HTTP_HDR_RESPONSE].b = TRUST_ME(http_StatusMessage(hp->status)); diff --git a/varnish-cache/bin/varnishtest/tests/r00325.vtc b/varnish-cache/bin/varnishtest/tests/r00325.vtc new file mode 100644 index 00000000..e3eabce6 --- /dev/null +++ b/varnish-cache/bin/varnishtest/tests/r00325.vtc @@ -0,0 +1,37 @@ +# $Id$ + +test "Check lack of response-string" + +server s1 { + rxreq + send "HTTP/1.1 200 \r\n" + send "Connection: close\r\n" + send "\r\n" + send "\r\n" + send "FOO\r\n" +} -start + +varnish v1 -vcl+backend {} -start + +client c1 { + txreq -url /bar + rxresp + expect resp.status == 200 + expect resp.msg == OK +} -run + +server s1 { + rxreq + send "HTTP/1.1 200\r\n" + send "Connection: close\r\n" + send "\r\n" + send "\r\n" + send "FOO\r\n" +} -start + +client c1 { + txreq -url /foo + rxresp + expect resp.status == 200 + expect resp.msg == OK +} -run -- 2.39.5