ifcfg-rh: fix vlan DEVICE parsing
authorDan Winship <danw@gnome.org>
Wed, 25 Apr 2012 18:40:04 +0000 (14:40 -0400)
committerDan Winship <danw@gnome.org>
Wed, 25 Apr 2012 18:56:51 +0000 (14:56 -0400)
A vlan DEVICE name must be either $(OTHERDEVICE).$(VLAN_ID) or
vlan$(VLAN_ID). Enforce that. In particular, don't:
(a) crash if the name has no "." and doesn't start with "vlan",
(b) loop forever if the $(VLAN_ID) part is non-numeric, or
(c) silently ignore non-numberic characters after the $(VLAN_ID).

src/settings/plugins/ifcfg-rh/reader.c

index 01d83c1..dd17ffb 100644 (file)
@@ -3732,8 +3732,8 @@ make_vlan_setting (shvarFile *ifcfg,
        char *value = NULL;
        char *iface_name = NULL;
        char *parent = NULL;
-       const char *p = NULL, *w;
-       gboolean has_numbers = FALSE;
+       const char *p = NULL;
+       char *end = NULL;
        gint vlan_id = -1;
        guint32 vlan_flags = 0;
 
@@ -3773,17 +3773,12 @@ make_vlan_setting (shvarFile *ifcfg,
                                p = iface_name + 4;
                }
 
-               w = p;
-               while (*w && !has_numbers)
-                       has_numbers = g_ascii_isdigit (*w);
-
-               /* Grab VLAN ID from interface name; this takes precedence over the
-                * separate VLAN_ID property for backwards compat.
-                */
-               if (has_numbers) {
-                       errno = 0;
-                       vlan_id = (gint) g_ascii_strtoll (p, NULL, 10);
-                       if (vlan_id < 0 || vlan_id > 4095 || errno) {
+               if (p) {
+                       /* Grab VLAN ID from interface name; this takes precedence over the
+                        * separate VLAN_ID property for backwards compat.
+                        */
+                       vlan_id = (gint) g_ascii_strtoll (p, &end, 10);
+                       if (vlan_id < 0 || vlan_id > 4095 || end == p || *end) {
                                g_set_error (error, IFCFG_PLUGIN_ERROR, 0,
                                             "Failed to determine VLAN ID from DEVICE '%s'",
                                             iface_name);