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

This commit is contained in:
Ronald Oussoren 2020-10-19 20:16:21 +02:00 committed by GitHub
parent 05ee790f4d
commit 93a1ccabde
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 18 additions and 0 deletions

View File

@ -1449,6 +1449,18 @@ class HandlerTests(unittest.TestCase):
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()

View File

@ -2596,6 +2596,11 @@ def _proxy_bypass_macosx_sysconf(host, proxy_settings):
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):

View File

@ -0,0 +1 @@
Ignore invalid prefix lengths in system proxy excludes.