Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 93a1cca

Browse files
authoredOct 19, 2020
bpo-41471: Ignore invalid prefix lengths in system proxy settings on macOS (pythonGH-22762)
1 parent 05ee790 commit 93a1cca

File tree

3 files changed

+18
-0
lines changed

3 files changed

+18
-0
lines changed
 

‎Lib/test/test_urllib2.py

+12
Original file line numberDiff line numberDiff line change
@@ -1449,6 +1449,18 @@ def test_osx_proxy_bypass(self):
14491449
bypass = {'exclude_simple': True, 'exceptions': []}
14501450
self.assertTrue(_proxy_bypass_macosx_sysconf('test', bypass))
14511451

1452+
# Check that invalid prefix lengths are ignored
1453+
bypass = {
1454+
'exclude_simple': False,
1455+
'exceptions': [ '10.0.0.0/40', '172.19.10.0/24' ]
1456+
}
1457+
host = '172.19.10.5'
1458+
self.assertTrue(_proxy_bypass_macosx_sysconf(host, bypass),
1459+
'expected bypass of %s to be True' % host)
1460+
host = '10.0.1.5'
1461+
self.assertFalse(_proxy_bypass_macosx_sysconf(host, bypass),
1462+
'expected bypass of %s to be False' % host)
1463+
14521464
def check_basic_auth(self, headers, realm):
14531465
with self.subTest(realm=realm, headers=headers):
14541466
opener = OpenerDirector()

‎Lib/urllib/request.py

+5
Original file line numberDiff line numberDiff line change
@@ -2596,6 +2596,11 @@ def ip2num(ipAddr):
25962596
mask = 8 * (m.group(1).count('.') + 1)
25972597
else:
25982598
mask = int(mask[1:])
2599+
2600+
if mask < 0 or mask > 32:
2601+
# System libraries ignore invalid prefix lengths
2602+
continue
2603+
25992604
mask = 32 - mask
26002605

26012606
if (hostIP >> mask) == (base >> mask):
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Ignore invalid prefix lengths in system proxy excludes.

0 commit comments

Comments
 (0)
Please sign in to comment.