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

jkonecny12 installerbot-noreply at redhat.com
Wed May 20 07:52:11 UTC 2015


From: Jiri Konecny <jkonecny at redhat.com>

Fix for bad input of ip addresses in text network spoke.
Change of check_ip_address funtion to check valid IP (4 or 6) when version is not
specified.
Change nameservers field to accept spaces.
---
 pyanaconda/network.py               | 12 +++++++++---
 pyanaconda/ui/tui/spokes/network.py | 21 ++++++++++++++++++---
 2 files changed, 27 insertions(+), 6 deletions(-)

diff --git a/pyanaconda/network.py b/pyanaconda/network.py
index b1d23bf..d073a8c 100644
--- a/pyanaconda/network.py
+++ b/pyanaconda/network.py
@@ -82,6 +82,10 @@ def check_ip_address(address, version=None):
         return False
     if version and version == ver:
         return True
+    elif not version:
+        return True
+    else:
+        return False
 
 def sanityCheckHostname(hostname):
     """
@@ -421,11 +425,13 @@ def _get_ip_setting_values_from_ksdata(networkdata):
     nss4 = []
     nss6 = []
     if networkdata.nameserver:
-        for ns in networkdata.nameserver.split(","):
-            if ":" in ns:
+        for ns in map(str.strip, networkdata.nameserver.split(",")):
+            if check_ip_address(ns, version=6):
                 nss6.append(nm.nm_ipv6_to_dbus_ay(ns))
-            else:
+            elif check_ip_address(ns, version=4):
                 nss4.append(nm.nm_ipv4_to_dbus_int(ns))
+            else:
+                log.error("IP address %s is not valid", ns)
     values.append(["ipv4", "dns", nss4, "au"])
     values.append(["ipv6", "dns", nss6, "aay"])
 
diff --git a/pyanaconda/ui/tui/spokes/network.py b/pyanaconda/ui/tui/spokes/network.py
index 6c71dee..b7d4e37 100644
--- a/pyanaconda/ui/tui/spokes/network.py
+++ b/pyanaconda/ui/tui/spokes/network.py
@@ -253,6 +253,20 @@ 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 = map(str.strip, value.split(self._separator))
+        if not addresses:
+            return False
+
+        for ip in addresses:
+            if not network.check_ip_address(ip):
+                return False
+        return True
+
 class ConfigureNetworkSpoke(EditTUISpoke):
     """ Spoke to set various configuration options for net devices. """
     title = N_("Device configuration")
@@ -260,14 +274,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/9e4a5cde33a1beac0894fc5ca6b29e5918e959da


More information about the anaconda-patches mailing list