Blame SOURCES/0148-fix-checkIP6-strip-leading-trailing-square-brackets.patch

ea8ea4
From 22d8707c95983104967465632aa7ece2bdf9e45d Mon Sep 17 00:00:00 2001
ea8ea4
From: Eric Garver <eric@garver.life>
ea8ea4
Date: Tue, 25 Feb 2020 16:16:04 -0500
ea8ea4
Subject: [PATCH 148/154] fix: checkIP6: strip leading/trailing square brackets
ea8ea4
ea8ea4
This lets users use URL encoded IPv6 addresses, e.g. "[::1234]" as
ea8ea4
opposed to "::1234". The brackets are typically only used in a URL or
ea8ea4
when combining an address with a port number, e.g. "[::1234]:22".
ea8ea4
ea8ea4
Fixes: rhbz 1779835
ea8ea4
(cherry picked from commit 46065ddfacd28aac46502a931085d27fe3571ebe)
ea8ea4
(cherry picked from commit 0fc443471f6a65e708f4dadc07519e27196c26e0)
ea8ea4
---
ea8ea4
 src/firewall/functions.py | 10 +++++++++-
ea8ea4
 1 file changed, 9 insertions(+), 1 deletion(-)
ea8ea4
ea8ea4
diff --git a/src/firewall/functions.py b/src/firewall/functions.py
ea8ea4
index 8793ac3dbf21..375302fd3d30 100644
ea8ea4
--- a/src/firewall/functions.py
ea8ea4
+++ b/src/firewall/functions.py
ea8ea4
@@ -177,6 +177,14 @@ def checkIP(ip):
ea8ea4
         return False
ea8ea4
     return True
ea8ea4
 
ea8ea4
+def normalizeIP6(ip):
ea8ea4
+    """ Normalize the IPv6 address
ea8ea4
+
ea8ea4
+    This is mostly about converting URL-like IPv6 address to normal ones.
ea8ea4
+    e.g. [1234::4321] --> 1234:4321
ea8ea4
+    """
ea8ea4
+    return ip.strip("[]")
ea8ea4
+
ea8ea4
 def checkIP6(ip):
ea8ea4
     """ Check IPv6 address.
ea8ea4
     
ea8ea4
@@ -185,7 +193,7 @@ def checkIP6(ip):
ea8ea4
     """
ea8ea4
 
ea8ea4
     try:
ea8ea4
-        socket.inet_pton(socket.AF_INET6, ip)
ea8ea4
+        socket.inet_pton(socket.AF_INET6, normalizeIP6(ip))
ea8ea4
     except socket.error:
ea8ea4
         return False
ea8ea4
     return True
ea8ea4
-- 
ea8ea4
2.25.2
ea8ea4