Blob Blame History Raw
From 736d0a4a401b3919cd5215908e166cd84798f8e2 Mon Sep 17 00:00:00 2001
From: Dan Winship <danw@gnome.org>
Date: Tue, 1 Apr 2014 15:05:29 -0400
Subject: [PATCH] ifcfg-rh: fix bugs in the new alias code (rh #1067170)

Fix a bug when reading an invalid alias file, where the code meant to
skip the rest of the loop iteration, but failed.

Also fix a memory leak and remove an unused variable.

Bugs noticed by coverity.
---
 src/settings/plugins/ifcfg-rh/reader.c | 16 ++++++++++------
 src/settings/plugins/ifcfg-rh/writer.c |  3 +--
 2 files changed, 11 insertions(+), 8 deletions(-)

diff --git a/src/settings/plugins/ifcfg-rh/reader.c b/src/settings/plugins/ifcfg-rh/reader.c
index 65142b9..70e58e9 100644
--- a/src/settings/plugins/ifcfg-rh/reader.c
+++ b/src/settings/plugins/ifcfg-rh/reader.c
@@ -1381,8 +1381,10 @@ make_ip4_setting (shvarFile *ifcfg,
 		NMIP4Address *addr = NULL;
 
 		addr = nm_ip4_address_new ();
-		if (!read_full_ip4_address (ifcfg, network_file, i, addr, error))
+		if (!read_full_ip4_address (ifcfg, network_file, i, addr, error)) {
+			nm_ip4_address_unref (addr);
 			goto done;
+		}
 		if (!nm_ip4_address_get_address (addr)) {
 			nm_ip4_address_unref (addr);
 
@@ -1551,11 +1553,13 @@ read_aliases (NMSettingIP4Config *s_ip4, const char *filename, const char *netwo
 			p = strchr (item, ':');
 			g_assert (p != NULL); /* we know this is true from utils_is_ifcfg_alias_file() */
 			for (p++; *p; p++) {
-				if (!g_ascii_isalnum (*p) && *p != '_') {
-					PLUGIN_WARN (IFCFG_PLUGIN_NAME, "    alias: ignoring alias file '%s' with invalid name", full_path);
-					g_free (full_path);
-					continue;
-				}
+				if (!g_ascii_isalnum (*p) && *p != '_')
+					break;
+			}
+			if (*p) {
+				PLUGIN_WARN (IFCFG_PLUGIN_NAME, "    alias: ignoring alias file '%s' with invalid name", full_path);
+				g_free (full_path);
+				continue;
 			}
 
 			parsed = svNewFile (full_path);
diff --git a/src/settings/plugins/ifcfg-rh/writer.c b/src/settings/plugins/ifcfg-rh/writer.c
index 720616d..5e962c5 100644
--- a/src/settings/plugins/ifcfg-rh/writer.c
+++ b/src/settings/plugins/ifcfg-rh/writer.c
@@ -2146,10 +2146,9 @@ write_ip4_aliases (NMConnection *connection, char *base_ifcfg_path)
 {
 	NMSettingIP4Config *s_ip4;
 	char *base_ifcfg_dir, *base_ifcfg_name, *base_name;
-	int i, num, base_ifcfg_path_len, base_ifcfg_name_len, base_name_len;
+	int i, num, base_ifcfg_name_len, base_name_len;
 	GDir *dir;
 
-	base_ifcfg_path_len = strlen (base_ifcfg_path);
 	base_ifcfg_dir = g_path_get_dirname (base_ifcfg_path);
 	base_ifcfg_name = g_path_get_basename (base_ifcfg_path);
 	base_ifcfg_name_len = strlen (base_ifcfg_name);
-- 
1.8.5.3