Skip to content

Commit e7c5a43

Browse files
bpo-41471: Ignore invalid prefix lengths in system proxy settings on macOS (GH-22762) (GH-22774)
(cherry picked from commit 93a1cca) Co-authored-by: Ronald Oussoren <[email protected]>
1 parent 65894ca commit e7c5a43

File tree

3 files changed

+18
-0
lines changed

3 files changed

+18
-0
lines changed

Lib/test/test_urllib2.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1444,6 +1444,18 @@ def test_osx_proxy_bypass(self):
14441444
bypass = {'exclude_simple': True, 'exceptions': []}
14451445
self.assertTrue(_proxy_bypass_macosx_sysconf('test', bypass))
14461446

1447+
# Check that invalid prefix lengths are ignored
1448+
bypass = {
1449+
'exclude_simple': False,
1450+
'exceptions': [ '10.0.0.0/40', '172.19.10.0/24' ]
1451+
}
1452+
host = '172.19.10.5'
1453+
self.assertTrue(_proxy_bypass_macosx_sysconf(host, bypass),
1454+
'expected bypass of %s to be True' % host)
1455+
host = '10.0.1.5'
1456+
self.assertFalse(_proxy_bypass_macosx_sysconf(host, bypass),
1457+
'expected bypass of %s to be False' % host)
1458+
14471459
def check_basic_auth(self, headers, realm):
14481460
with self.subTest(realm=realm, headers=headers):
14491461
opener = OpenerDirector()

Lib/urllib/request.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2604,6 +2604,11 @@ def ip2num(ipAddr):
26042604
mask = 8 * (m.group(1).count('.') + 1)
26052605
else:
26062606
mask = int(mask[1:])
2607+
2608+
if mask < 0 or mask > 32:
2609+
# System libraries ignore invalid prefix lengths
2610+
continue
2611+
26072612
mask = 32 - mask
26082613

26092614
if (hostIP >> mask) == (base >> mask):
Lines changed: 1 addition & 0 deletions
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)