]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Issue #17849: Raise sensible exception for invalid HTTP tunnel response
authorMartin Panter <vadmium>
Mon, 7 Sep 2015 01:18:47 +0000 (01:18 +0000)
committerMartin Panter <vadmium>
Mon, 7 Sep 2015 01:18:47 +0000 (01:18 +0000)
Initial patch from Cory Benfield.

Lib/httplib.py
Lib/test/test_httplib.py
Misc/ACKS
Misc/NEWS

index fc908d214dff25c6aeeb9c2ad23b0d6e84eb0f7e..7223ba151271f16d0eedad83b49a0961b59fc674 100644 (file)
@@ -810,6 +810,11 @@ class HTTPConnection:
                                        method = self._method)
         (version, code, message) = response._read_status()
 
+        if version == "HTTP/0.9":
+            # HTTP/0.9 doesn't support the CONNECT verb, so if httplib has
+            # concluded HTTP/0.9 is being used something has gone wrong.
+            self.close()
+            raise socket.error("Invalid response from tunnel request")
         if code != 200:
             self.close()
             raise socket.error("Tunnel connection failed: %d %s" % (code,
index 301458910d6bd82e8027878dccfb7c897944d4ce..a72f6f7ff1c27ce6395a76ae71ba92ce1924fbac 100644 (file)
@@ -578,6 +578,16 @@ class BasicTest(TestCase):
         #self.assertTrue(response[0].closed)
         self.assertTrue(conn.sock.file_closed)
 
+    def test_proxy_tunnel_without_status_line(self):
+        # Issue 17849: If a proxy tunnel is created that does not return
+        # a status code, fail.
+        body = 'hello world'
+        conn = httplib.HTTPConnection('example.com', strict=False)
+        conn.set_tunnel('foo')
+        conn.sock = FakeSocket(body)
+        with self.assertRaisesRegexp(socket.error, "Invalid response"):
+            conn._tunnel()
+
 class OfflineTest(TestCase):
     def test_responses(self):
         self.assertEqual(httplib.responses[httplib.NOT_FOUND], "Not Found")
index ba3e3fe64791a2b90b24823d348985dd6a4e7b83..59d0914c1f40f5a6a22337b212a5b483db655338 100644 (file)
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -107,6 +107,7 @@ Ben Bell
 Thomas Bellman
 Alexander “Саша” Belopolsky
 Eli Bendersky
+Cory Benfield
 David Benjamin
 Oscar Benjamin
 Andrew Bennetts
index 017acc611d54244955ca86b059ffa117fd4a087d..26e41c334c9d37094d42fa0c0c45b5b95770ccbd 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -37,6 +37,10 @@ Core and Builtins
 Library
 -------
 
+- Issue #17849: Raise a sensible exception if an invalid response is
+  received for a HTTP tunnel request, as seen with some servers that
+  do not support tunnelling.  Initial patch from Cory Benfield.
+
 - Issue #16180: Exit pdb if file has syntax error, instead of trapping user
   in an infinite loop.  Patch by Xavier de Gaye.