[PATCH] be more defensive -- check values for nonsenses

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



---
 loader/kickstart.c |    2 +
 loader/net.c       |   58 ++++++++++++++++++++++++++++++++++++++-------------
 loader/net.h       |    2 +
 3 files changed, 47 insertions(+), 15 deletions(-)

diff --git a/loader/kickstart.c b/loader/kickstart.c
index 60163ee..f96a7a9 100644
--- a/loader/kickstart.c
+++ b/loader/kickstart.c
@@ -651,6 +651,8 @@ int process_kickstart_wifi (struct loaderData_s * loaderData) {
     int rc = -1;
 
     if (loaderData->essid != NULL) {
+        checkIPsettings(&(loaderData->ipinfo_set), &(loaderData->ipv4), 
+                &(loaderData->gateway), &(loaderData->netmask));
         if (loaderData->wepkey != NULL) {
             rc = add_and_activate_wifi_connection(&(loaderData->netDev), loaderData->essid,
                     WIFI_PROTECTION_WEP, loaderData->wepkey, loaderData->ipinfo_set, loaderData->ipv4,
diff --git a/loader/net.c b/loader/net.c
index 7275a4b..3b6d7ef 100644
--- a/loader/net.c
+++ b/loader/net.c
@@ -1768,6 +1768,8 @@ int kickstartNetworkUp(struct loaderData_s * loaderData, iface_t * iface) {
     iface_init_iface_t(iface);
 
     if (loaderData->essid != NULL) {
+        checkIPsettings(&(loaderData->ipinfo_set), &(loaderData->ipv4), &(loaderData->gateway),
+                &(loaderData->netmask));
         if (loaderData->wepkey != NULL)
             rc = add_and_activate_wifi_connection(&(loaderData->netDev),
                     loaderData->essid, WIFI_PROTECTION_WEP, loaderData->wepkey,
@@ -2228,12 +2230,14 @@ add_cb(NMClient *client,
     if (error) logMessage(ERROR, "Error adding wifi connection: %s", error->message);
 }
 
-gint64 ip_str_to_nbo(char* ip) {
+gboolean ip_str_to_nbo(char* ip, guint32 *result) {
     //get NBO representation of ip address
     struct in_addr tmp_addr = { 0 };
 
-    if (inet_pton(AF_INET, ip, &tmp_addr) == 1) return tmp_addr.s_addr;
-    else return -1;
+    if (inet_pton(AF_INET, ip, &tmp_addr) == 1) {
+        *result = tmp_addr.s_addr;
+        return TRUE;
+    } else return FALSE;
 }
 
 
@@ -2360,20 +2364,20 @@ int add_and_activate_wifi_connection(char **iface, char *ssid,
     if (ip_method_manual) {
         GPtrArray *addresses = g_ptr_array_new();
         GArray *address_array = g_array_new(FALSE, FALSE, sizeof(guint32));
-        guint32 nbo_ip = ip_str_to_nbo(address);
+        guint32 nbo_ip = 0;
         guint32 nbo_gw = 0;
         guint32 nbo_dns = 0;
-        gint64 nbo_netmask = -1;
+        guint32 nbo_netmask = 0;
         guint32 nbo_prefix = 0;
         char *dns_addr = NULL;
 
-        if (gateway) nbo_gw = ip_str_to_nbo(gateway);
-        if (netmask) {
-            nbo_netmask = ip_str_to_nbo(netmask);
-        }
-        nbo_prefix = nbo_netmask >= 0 ?
-                        nm_utils_ip4_netmask_to_prefix((guint32) nbo_netmask) :
-                        nm_utils_ip4_get_default_prefix(nbo_ip);
+        ip_str_to_nbo(address, &nbo_ip);
+
+        if (gateway) ip_str_to_nbo(gateway, &nbo_gw);
+
+        nbo_prefix = nm_utils_ip4_get_default_prefix(nbo_ip);
+        if (netmask && ip_str_to_nbo(netmask, &nbo_netmask))
+                nbo_prefix = nm_utils_ip4_netmask_to_prefix(nbo_netmask);
 
         g_array_append_val(address_array, nbo_ip);
         g_array_append_val(address_array, nbo_prefix);
@@ -2391,10 +2395,11 @@ int add_and_activate_wifi_connection(char **iface, char *ssid,
             buf = strdup(dns);
             dns_addr = strtok(buf, ",");
             while (dns_addr && count <= MAXNS) {
-                nbo_dns = ip_str_to_nbo(dns_addr);
-                nm_setting_ip4_config_add_dns(s_ip, nbo_dns);
+                if (ip_str_to_nbo(dns_addr, &nbo_dns)) {
+                    nm_setting_ip4_config_add_dns(s_ip, nbo_dns);
+                    count++;
+                }
                 dns_addr = strtok(NULL, ",");
-                count++;
             }
         }
         nm_connection_add_setting(connection, NM_SETTING (s_ip));
@@ -2419,4 +2424,27 @@ int add_and_activate_wifi_connection(char **iface, char *ssid,
     return WIFI_ACTIVATION_TIMED_OUT;
 }
 
+gboolean checkIPsettings (int *ip_info_set, char **ip, char **gateway, char **netmask) {
+    gboolean ok = TRUE;
+    guint32 tmp = 0;
+
+    if (*ip && !ip_str_to_nbo(*ip, &tmp)) {
+        free(*ip);
+        *ip = NULL;
+        *ip_info_set = 0;
+        ok = FALSE;
+    }
+    if (*gateway && !ip_str_to_nbo(*gateway, &tmp)) {
+        free(*gateway);
+        *gateway = NULL;
+        ok = FALSE;
+    }
+    if (*netmask && !ip_str_to_nbo(*netmask, &tmp)) {
+        free(*netmask);
+        *netmask = NULL;
+        ok = FALSE;
+    }
+    return ok;
+}
+
 /* vim:set shiftwidth=4 softtabstop=4: */
diff --git a/loader/net.h b/loader/net.h
index 4a133d6..95b659f 100644
--- a/loader/net.h
+++ b/loader/net.h
@@ -87,6 +87,8 @@ int add_and_activate_wifi_connection (char **iface, char *ssid,
 				      int ip_method_manual, char *address,
                                       char *gateway, char *dns,
                                       char *netmask);
+int checkIPsettings (int *ip_info_set, char **ip, char **gateway,
+                     char **netmask);
 #ifdef ENABLE_IPV6
 int isValidIPv6Address(const char *address);
 #endif
-- 
1.7.4.4

_______________________________________________
Anaconda-devel-list mailing list
Anaconda-devel-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/anaconda-devel-list


[Index of Archives]     [Kickstart]     [Fedora Users]     [Fedora Legacy List]     [Fedora Maintainers]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [Yosemite Photos]     [KDE Users]     [Fedora Tools]
  Powered by Linux