bpo-41471: Ignore invalid prefix lengths in system proxy settings on macOS (GH-22762) (GH-22773)
(cherry picked from commit 93a1ccabdede416425473329b8c718d507c55e29)
Co-authored-by: Ronald Oussoren <ronaldoussoren@mac.com>
diff --git a/Lib/urllib/request.py b/Lib/urllib/request.py
index 2a3d715..a8c870b 100644
--- a/Lib/urllib/request.py
+++ b/Lib/urllib/request.py
@@ -2596,6 +2596,11 @@
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):