# HG changeset patch # User Michele OrrĂ¹ # Date 1377628081 -3600 # Tue Aug 27 19:28:01 2013 +0100 # Branch issue/16083 # Node ID 4022446d23c3eb2fd549790c83a4502099c60caf # Parent 0872257752c2d57a8bf61defe11b57f4c7820ba4 Fixing #16803: HTTPServer does not correctly handle bad request line. diff -r 0872257752c2 -r 4022446d23c3 Lib/http/server.py --- a/Lib/http/server.py Tue Aug 27 20:17:03 2013 +0300 +++ b/Lib/http/server.py Tue Aug 27 19:28:01 2013 +0100 @@ -699,8 +699,13 @@ """ path = self.translate_path(self.path) - f = None - if os.path.isdir(path): + try: + isdir = os.path.isdir(path) + except TypeError: + # client sent invalid bytes, see issue #16083 + self.send_error(400) + return + if isdir: if not self.path.endswith('/'): # redirect browser - doing basically what apache does self.send_response(301) diff -r 0872257752c2 -r 4022446d23c3 Lib/test/test_httpservers.py --- a/Lib/test/test_httpservers.py Tue Aug 27 20:17:03 2013 +0300 +++ b/Lib/test/test_httpservers.py Tue Aug 27 19:28:01 2013 +0100 @@ -306,6 +306,9 @@ self.check_status_and_reason(response, 501) response = self.request('/', method='GETs') self.check_status_and_reason(response, 501) + # send NUL byte. See issue #16083 + response = self.request('/\00', method='GET') + self.check_status_and_reason(response, 400) cgi_file1 = """\