Skip to content

Commit aa7b03b

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

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
@@ -1447,6 +1447,18 @@ def test_osx_proxy_bypass(self):
14471447
bypass = {'exclude_simple': True, 'exceptions': []}
14481448
self.assertTrue(_proxy_bypass_macosx_sysconf('test', bypass))
14491449

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

Lib/urllib/request.py

Lines changed: 5 additions & 0 deletions
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):
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)