]> granicus.if.org Git - python/commitdiff
Issue #14036: return None when port in urlparse cross 65535
authorSenthil Kumaran <senthil@uthcode.com>
Thu, 24 May 2012 13:56:17 +0000 (21:56 +0800)
committerSenthil Kumaran <senthil@uthcode.com>
Thu, 24 May 2012 13:56:17 +0000 (21:56 +0800)
Lib/test/test_urlparse.py
Lib/urllib/parse.py
Misc/NEWS

index 73150cffa65a0f54a8e8fb3368e7ad57506901b9..e9adaefbd5ab6447b6648949989d2bdfc7e7b2ec 100755 (executable)
@@ -524,6 +524,11 @@ class UrlParseTestCase(unittest.TestCase):
         self.assertEqual(p.port, 80)
         self.assertEqual(p.geturl(), url)
 
+        # Verify an illegal port is returned as None
+        url = b"HTTP://WWW.PYTHON.ORG:65536/doc/#frag"
+        p = urllib.parse.urlsplit(url)
+        self.assertEqual(p.port, None)
+
     def test_attributes_bad_port(self):
         """Check handling of non-integer ports."""
         p = urllib.parse.urlsplit("http://www.example.net:foo")
index 92170ad0a2435907ab06f6e3404dccdad1986869..528c0a7aafb1bcce85a6bbcc992f6da8960ac776 100644 (file)
@@ -143,6 +143,9 @@ class _NetlocResultMixinBase(object):
         port = self._hostinfo[1]
         if port is not None:
             port = int(port, 10)
+            # Return None on an illegal port
+            if not ( 0 <= port <= 65535):
+                return None
         return port
 
 
index 7ed8f152f9cfff4aca1e3165b6a47c5882f2515c..d9b8b5cf846c700b19fae7adbdcf87529bb42a94 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -67,6 +67,9 @@ Core and Builtins
 Library
 -------
 
+- Issue #14036: Add an additional check to validate that port in urlparse does
+  not go in illegal range and returns None.
+
 - Issue #14875: Use float('inf') instead of float('1e66666') in the json module.
 
 - Issue #14426: Correct the Date format in Expires attribute of Set-Cookie