Blame SOURCES/00325-CVE-2019-9948.patch

dd3773
diff --git a/Lib/test/test_urllib.py b/Lib/test/test_urllib.py
dd3773
index 649a5b8..0061a52 100644
dd3773
--- a/Lib/test/test_urllib.py
dd3773
+++ b/Lib/test/test_urllib.py
dd3773
@@ -16,6 +16,7 @@ except ImportError:
dd3773
     ssl = None
dd3773
 import sys
dd3773
 import tempfile
dd3773
+import warnings
dd3773
 from nturl2path import url2pathname, pathname2url
dd3773
 
dd3773
 from base64 import b64encode
dd3773
@@ -1463,6 +1464,23 @@ class URLopener_Tests(unittest.TestCase):
dd3773
                 "spam://c:|windows%/:=&?~#+!$,;'@()*[]|/path/"),
dd3773
                 "//c:|windows%/:=&?~#+!$,;'@()*[]|/path/")
dd3773
 
dd3773
+    def test_local_file_open(self):
dd3773
+        # bpo-35907, CVE-2019-9948: urllib must reject local_file:// scheme
dd3773
+        class DummyURLopener(urllib.request.URLopener):
dd3773
+            def open_local_file(self, url):
dd3773
+                return url
dd3773
+
dd3773
+        with warnings.catch_warnings(record=True):
dd3773
+            warnings.simplefilter("ignore", DeprecationWarning)
dd3773
+
dd3773
+            for url in ('local_file://example', 'local-file://example'):
dd3773
+                self.assertRaises(OSError, urllib.request.urlopen, url)
dd3773
+                self.assertRaises(OSError, urllib.request.URLopener().open, url)
dd3773
+                self.assertRaises(OSError, urllib.request.URLopener().retrieve, url)
dd3773
+                self.assertRaises(OSError, DummyURLopener().open, url)
dd3773
+                self.assertRaises(OSError, DummyURLopener().retrieve, url)
dd3773
+
dd3773
+
dd3773
 # Just commented them out.
dd3773
 # Can't really tell why keep failing in windows and sparc.
dd3773
 # Everywhere else they work ok, but on those machines, sometimes
dd3773
diff --git a/Lib/urllib/request.py b/Lib/urllib/request.py
dd3773
index d28f2f8..c9945d9 100644
dd3773
--- a/Lib/urllib/request.py
dd3773
+++ b/Lib/urllib/request.py
dd3773
@@ -1747,7 +1747,7 @@ class URLopener:
dd3773
         name = 'open_' + urltype
dd3773
         self.type = urltype
dd3773
         name = name.replace('-', '_')
dd3773
-        if not hasattr(self, name):
dd3773
+        if not hasattr(self, name) or name == 'open_local_file':
dd3773
             if proxy:
dd3773
                 return self.open_unknown_proxy(proxy, fullurl, data)
dd3773
             else: