Mailing List Archive

bpo-41471: Ignore invalid prefix lengths in system proxy settings on macOS (GH-22762) (GH-22774)
https://github.com/python/cpython/commit/e7c5a43984f82ef9634cb0b2b8c4750b2fd431a0
commit: e7c5a43984f82ef9634cb0b2b8c4750b2fd431a0
branch: 3.8
author: Miss Skeleton (bot) <31488909+miss-islington@users.noreply.github.com>
committer: GitHub <noreply@github.com>
date: 2020-10-20T09:17:58+02:00
summary:

bpo-41471: Ignore invalid prefix lengths in system proxy settings on macOS (GH-22762) (GH-22774)

(cherry picked from commit 93a1ccabdede416425473329b8c718d507c55e29)

Co-authored-by: Ronald Oussoren <ronaldoussoren@mac.com>

files:
A Misc/NEWS.d/next/macOS/2020-10-19-12-25-19.bpo-41471.gwA7un.rst
M Lib/test/test_urllib2.py
M Lib/urllib/request.py

diff --git a/Lib/test/test_urllib2.py b/Lib/test/test_urllib2.py
index 091b3979aa680..0132059fdb0ad 100644
--- a/Lib/test/test_urllib2.py
+++ b/Lib/test/test_urllib2.py
@@ -1444,6 +1444,18 @@ def test_osx_proxy_bypass(self):
bypass = {'exclude_simple': True, 'exceptions': []}
self.assertTrue(_proxy_bypass_macosx_sysconf('test', bypass))

+ # Check that invalid prefix lengths are ignored
+ bypass = {
+ 'exclude_simple': False,
+ 'exceptions': [ '10.0.0.0/40', '172.19.10.0/24' ]
+ }
+ host = '172.19.10.5'
+ self.assertTrue(_proxy_bypass_macosx_sysconf(host, bypass),
+ 'expected bypass of %s to be True' % host)
+ host = '10.0.1.5'
+ self.assertFalse(_proxy_bypass_macosx_sysconf(host, bypass),
+ 'expected bypass of %s to be False' % host)
+
def check_basic_auth(self, headers, realm):
with self.subTest(realm=realm, headers=headers):
opener = OpenerDirector()
diff --git a/Lib/urllib/request.py b/Lib/urllib/request.py
index e44073886a6cd..afd634159fa82 100644
--- a/Lib/urllib/request.py
+++ b/Lib/urllib/request.py
@@ -2604,6 +2604,11 @@ def ip2num(ipAddr):
mask = 8 * (m.group(1).count('.') + 1)
else:
mask = int(mask[1:])
+
+ if mask < 0 or mask > 32:
+ # System libraries ignore invalid prefix lengths
+ continue
+
mask = 32 - mask

if (hostIP >> mask) == (base >> mask):
diff --git a/Misc/NEWS.d/next/macOS/2020-10-19-12-25-19.bpo-41471.gwA7un.rst b/Misc/NEWS.d/next/macOS/2020-10-19-12-25-19.bpo-41471.gwA7un.rst
new file mode 100644
index 0000000000000..db5dd00b19b0d
--- /dev/null
+++ b/Misc/NEWS.d/next/macOS/2020-10-19-12-25-19.bpo-41471.gwA7un.rst
@@ -0,0 +1 @@
+Ignore invalid prefix lengths in system proxy excludes.

_______________________________________________
Python-checkins mailing list
Python-checkins@python.org
https://mail.python.org/mailman/listinfo/python-checkins