diff --git a/src/buffer.c b/src/buffer.c index 7019beb4..9af4a238 100644 --- a/src/buffer.c +++ b/src/buffer.c @@ -893,6 +893,11 @@ int buffer_path_simplify(buffer *dest, buffer *src) } *(out++) = pre1; + if (pre1 == '\0') { + dest->used = (out - start) + 1; + return 0; + } + while (1) { if (c == '/' || c == '\0') { toklen = out - slash; diff --git a/src/request.c b/src/request.c index 966b00e5..5ff7f733 100644 --- a/src/request.c +++ b/src/request.c @@ -483,6 +483,21 @@ int http_request_parse(server *srv, connection *con) { } in_folding = 0; + + if (con->request.uri->used == 1) { + con->http_status = 400; + con->response.keep_alive = 0; + con->keep_alive = 0; + + log_error_write(srv, __FILE__, __LINE__, "s", "no uri specified -> 400"); + if (srv->srvconf.log_request_header_on_error) { + log_error_write(srv, __FILE__, __LINE__, "Sb", + "request-header:\n", + con->request.request); + } + return 0; + } + for (; i < con->parse_request->used && !done; i++) { char *cur = con->parse_request->ptr + i; diff --git a/tests/core-request.t b/tests/core-request.t index f6a486aa..f4db9376 100755 --- a/tests/core-request.t +++ b/tests/core-request.t @@ -8,7 +8,7 @@ BEGIN { use strict; use IO::Socket; -use Test::More tests => 31; +use Test::More tests => 33; use LightyTest; my $tf = LightyTest->new(); @@ -259,6 +259,20 @@ EOF $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'Content-Type' => 'application/octet-stream' } ]; ok($tf->handle_http($t) == 0, 'Content-Type - unknown'); +$t->{REQUEST} = ( <{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 400 } ]; +ok($tf->handle_http($t) == 0, 'empty request-URI'); + +$t->{REQUEST} = ( <{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } ]; +ok($tf->handle_http($t) == 0, 'uppercase filenames'); + ok($tf->stop_proc == 0, "Stopping lighttpd"); diff --git a/tests/prepare.sh b/tests/prepare.sh index 3ac4943b..d7e38ab6 100755 --- a/tests/prepare.sh +++ b/tests/prepare.sh @@ -41,6 +41,7 @@ cp $srcdir/lighttpd.htpasswd $tmpdir/ cp $srcdir/var-include-sub.conf $tmpdir/../ touch $tmpdir/servers/www.example.org/pages/image.jpg \ $tmpdir/servers/www.example.org/pages/image.JPG \ + $tmpdir/servers/www.example.org/pages/Foo.txt \ $tmpdir/servers/www.example.org/pages/a printf "%-40s" "preparing infrastructure"