From 1fed78619fa71675f3ae902abbafe65526a04f7c Mon Sep 17 00:00:00 2001 From: "P. Christeas" Date: Tue, 23 Nov 2010 17:35:58 +0200 Subject: [PATCH] websrv_lib: abort request on partial headers. While searching for the KTHML bug, noticed that partial http requests would falsely be honoured. Instead, we must check if the full headers (including the blank line) have been parsed before we dispatch the request to the virtual handler class. Conflicts: bin/service/websrv_lib.py bzr revid: p_christ@hol.gr-20101123153558-oh44mjkhwjaebwow --- bin/service/websrv_lib.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/bin/service/websrv_lib.py b/bin/service/websrv_lib.py index 58bc6508245..5b17191b493 100644 --- a/bin/service/websrv_lib.py +++ b/bin/service/websrv_lib.py @@ -255,6 +255,12 @@ class MultiHTTPHandler(FixSendError, HttpOptions, BaseHTTPRequestHandler): fore.raw_requestline = "%s %s %s\n" % (self.command, path, self.version) if not fore.parse_request(): # An error code has been sent, just exit return + if fore.headers.status: + self.log_error("Parse error at headers: %s", fore.headers.status) + self.close_connection = 1 + self.send_error(400,"Parse error at HTTP headers") + return + self.request_version = fore.request_version if auth_provider and auth_provider.realm: try: @@ -413,8 +419,14 @@ class MultiHTTPHandler(FixSendError, HttpOptions, BaseHTTPRequestHandler): hnd.rfile = self.rfile hnd.wfile = self.wfile self.rlpath = self.raw_requestline - self._handle_one_foreign(hnd,npath, vdir.auth_provider) - # print "Handled, closing = ", self.close_connection + try: + self._handle_one_foreign(hnd,npath, vdir.auth_provider) + except IOError, e: + if e.errno == errno.EPIPE: + self.log_message("Could not complete request %s," \ + "client closed connection", self.rlpath.rstrip()) + else: + raise return # if no match: self.send_error(404, "Path not found: %s" % self.path)