From f378457f2521aedf1b398447ff0d01dac72a4b7f Mon Sep 17 00:00:00 2001 From: Dan Winship Date: Wed, 25 Apr 2012 14:40:04 -0400 Subject: [PATCH] ifcfg-rh: fix vlan DEVICE parsing 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 | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/src/settings/plugins/ifcfg-rh/reader.c b/src/settings/plugins/ifcfg-rh/reader.c index 01d83c1b2b..dd17ffbc56 100644 --- a/src/settings/plugins/ifcfg-rh/reader.c +++ b/src/settings/plugins/ifcfg-rh/reader.c @@ -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);