[master 1/2] Fix bad check of illegal ip address

jkonecny12 installerbot-noreply at redhat.com
Wed May 6 13:18:07 UTC 2015


From: Jiri Konecny <jkonecny at redhat.com>

Fix for bad check of input ip addresses in text network spoke.
---
 pyanaconda/ui/tui/spokes/network.py | 22 +++++++++++++++++++---
 1 file changed, 19 insertions(+), 3 deletions(-)

diff --git a/pyanaconda/ui/tui/spokes/network.py b/pyanaconda/ui/tui/spokes/network.py
index 6c71dee..ca0f74a 100644
--- a/pyanaconda/ui/tui/spokes/network.py
+++ b/pyanaconda/ui/tui/spokes/network.py
@@ -253,6 +253,21 @@ def match(self, value):
                 return False
         return network.check_ip_address(addr, version=6)
 
+class Fake_RE_Nameservers(object):
+    def __init__(self, separator):
+        self.separator = separator
+
+    def match(self, value):
+        addresses = value.split(self.separator)
+        if not addresses:
+            return False
+
+        regex = re.compile("^" + IPV4_PATTERN_WITHOUT_ANCHORS + "$")
+        for ip in addresses:
+            if not regex.match(ip) and not network.check_ip_address(ip, version=6):
+                return False
+        return True
+
 class ConfigureNetworkSpoke(EditTUISpoke):
     """ Spoke to set various configuration options for net devices. """
     title = N_("Device configuration")
@@ -260,14 +275,15 @@ class ConfigureNetworkSpoke(EditTUISpoke):
 
     edit_fields = [
         Entry(N_('IPv4 address or %s for DHCP') % '"dhcp"', "ip",
-              re.compile("^" + IPV4_PATTERN_WITHOUT_ANCHORS + "|dhcp$"), True),
+              re.compile("^(?:" + IPV4_PATTERN_WITHOUT_ANCHORS + "|dhcp)$"), True),
         Entry(N_("IPv4 netmask"), "netmask", re.compile("^" + IPV4_PATTERN_WITHOUT_ANCHORS + "$"), True),
         Entry(N_("IPv4 gateway"), "gateway", re.compile("^" + IPV4_PATTERN_WITHOUT_ANCHORS + "$"), True),
         Entry(N_('IPv6 address or %(auto)s for automatic, %(dhcp)s for DHCP, %(ignore)s to turn off')
               % {"auto": '"auto"', "dhcp": '"dhcp"', "ignore": '"ignore"'}, "ipv6",
               Fake_RE_IPV6(allow_prefix=True, whitelist=["auto", "dhcp", "ignore"]), True),
-        Entry(N_("IPv6 default gateway"), "ipv6gateway", re.compile(".*$"), True),
-        Entry(N_("Nameservers (comma separated)"), "nameserver", re.compile(".*$"), True),
+        Entry(N_("IPv6 default gateway"), "ipv6gateway", Fake_RE_IPV6(), True),
+        Entry(N_("Nameservers (comma separated)"), "nameserver",
+              Fake_RE_Nameservers(separator=","), True),
         Entry(N_("Connect automatically after reboot"), "onboot", EditTUISpoke.CHECK, True),
         Entry(N_("Apply configuration in installer"), "_apply", EditTUISpoke.CHECK, True),
     ]


-- 
To view this commit on github, visit https://github.com/rhinstaller/anaconda/commit/cccd90fab9ddbf0517ea57eb4b0e5b057e748cee


More information about the anaconda-patches mailing list