Blame SOURCES/1017-initrd-parse-rd.net.dhcp.vendor-class-rh1870692.patch

146a1d
From d15b8c6c561258eb0e0b92d6176a16ccc8c23be3 Mon Sep 17 00:00:00 2001
146a1d
From: Antonio Cardace <acardace@redhat.com>
146a1d
Date: Thu, 27 Aug 2020 18:18:31 +0200
146a1d
Subject: [PATCH 1/4] core: add 'dhcp-vendor-class-identifier' validation
146a1d
 function
146a1d
146a1d
So that it can be reused.
146a1d
146a1d
Signed-off-by: Antonio Cardace <acardace@redhat.com>
146a1d
(cherry picked from commit 5cca669ff39c6909be906e8974e424ffd2ea42c2)
146a1d
(cherry picked from commit 847488cb2f9f0ba8017938e0876677180c0c91a0)
146a1d
---
146a1d
 .../nm-libnm-core-utils.c                     | 55 +++++++++++++++++++
146a1d
 .../nm-libnm-core-utils.h                     |  2 +
146a1d
 libnm-core/nm-setting-ip4-config.c            | 48 +---------------
146a1d
 po/POTFILES.in                                |  1 +
146a1d
 src/devices/nm-device.c                       | 11 ++--
146a1d
 5 files changed, 65 insertions(+), 52 deletions(-)
146a1d
146a1d
diff --git a/libnm-core/nm-libnm-core-intern/nm-libnm-core-utils.c b/libnm-core/nm-libnm-core-intern/nm-libnm-core-utils.c
146a1d
index f2c85cc60..8be7d913f 100644
146a1d
--- a/libnm-core/nm-libnm-core-intern/nm-libnm-core-utils.c
146a1d
+++ b/libnm-core/nm-libnm-core-intern/nm-libnm-core-utils.c
146a1d
@@ -6,6 +6,8 @@
146a1d
 
146a1d
 #include "nm-common-macros.h"
146a1d
 
146a1d
+#include "nm-errors.h"
146a1d
+
146a1d
 #include <linux/rtnetlink.h>
146a1d
 
146a1d
 /*****************************************************************************/
146a1d
@@ -257,3 +259,56 @@ NM_UTILS_ENUM2STR_DEFINE (nm_utils_route_type2str, guint8,
146a1d
 	NM_UTILS_ENUM2STR (RTN_UNREACHABLE, "unreachable"),
146a1d
 	NM_UTILS_ENUM2STR (RTN_UNSPEC, "unspecified"),
146a1d
 );
146a1d
+
146a1d
+gboolean
146a1d
+nm_utils_validate_dhcp4_vendor_class_id (const char *vci, GError **error)
146a1d
+{
146a1d
+	const char *  bin;
146a1d
+	gsize         unescaped_len;
146a1d
+	gs_free char *to_free = NULL;
146a1d
+
146a1d
+	g_return_val_if_fail (!error || !(*error), FALSE);
146a1d
+	g_return_val_if_fail (vci, FALSE);
146a1d
+
146a1d
+	if (vci[0] == '\0') {
146a1d
+		g_set_error_literal (error,
146a1d
+		                     NM_CONNECTION_ERROR,
146a1d
+		                     NM_CONNECTION_ERROR_INVALID_PROPERTY,
146a1d
+		                     _ ("property cannot be an empty string"));
146a1d
+		g_prefix_error (error,
146a1d
+		                "%s.%s: ",
146a1d
+		                NM_SETTING_IP4_CONFIG_SETTING_NAME,
146a1d
+		                NM_SETTING_IP4_CONFIG_DHCP_VENDOR_CLASS_IDENTIFIER);
146a1d
+		return FALSE;
146a1d
+	}
146a1d
+
146a1d
+	bin = nm_utils_buf_utf8safe_unescape (vci,
146a1d
+	                                      NM_UTILS_STR_UTF8_SAFE_FLAG_NONE,
146a1d
+	                                      &unescaped_len,
146a1d
+	                                      (gpointer *) &to_free);
146a1d
+	/* a DHCP option cannot be longer than 255 bytes */
146a1d
+	if (unescaped_len > 255) {
146a1d
+		g_set_error_literal (error,
146a1d
+		                     NM_CONNECTION_ERROR,
146a1d
+		                     NM_CONNECTION_ERROR_INVALID_PROPERTY,
146a1d
+		                     _ ("property cannot be longer than 255 bytes"));
146a1d
+		g_prefix_error (error,
146a1d
+		                "%s.%s: ",
146a1d
+		                NM_SETTING_IP4_CONFIG_SETTING_NAME,
146a1d
+		                NM_SETTING_IP4_CONFIG_DHCP_VENDOR_CLASS_IDENTIFIER);
146a1d
+		return FALSE;
146a1d
+	}
146a1d
+	if (strlen (bin) != unescaped_len) {
146a1d
+		g_set_error_literal (error,
146a1d
+		                     NM_CONNECTION_ERROR,
146a1d
+		                     NM_CONNECTION_ERROR_INVALID_PROPERTY,
146a1d
+		                     _ ("property cannot contain any nul bytes"));
146a1d
+		g_prefix_error (error,
146a1d
+		                "%s.%s: ",
146a1d
+		                NM_SETTING_IP4_CONFIG_SETTING_NAME,
146a1d
+		                NM_SETTING_IP4_CONFIG_DHCP_VENDOR_CLASS_IDENTIFIER);
146a1d
+		return FALSE;
146a1d
+	}
146a1d
+
146a1d
+	return TRUE;
146a1d
+}
146a1d
diff --git a/libnm-core/nm-libnm-core-intern/nm-libnm-core-utils.h b/libnm-core/nm-libnm-core-intern/nm-libnm-core-utils.h
146a1d
index bb3fa5fcf..6c1337d88 100644
146a1d
--- a/libnm-core/nm-libnm-core-intern/nm-libnm-core-utils.h
146a1d
+++ b/libnm-core/nm-libnm-core-intern/nm-libnm-core-utils.h
146a1d
@@ -140,4 +140,6 @@ guint8 nm_utils_route_type_by_name (const char *name);
146a1d
 
146a1d
 const char *nm_utils_route_type2str (guint8 val, char *buf, gsize len);
146a1d
 
146a1d
+gboolean nm_utils_validate_dhcp4_vendor_class_id (const char *vci, GError **error);
146a1d
+
146a1d
 #endif /* __NM_LIBNM_SHARED_UTILS_H__ */
146a1d
diff --git a/libnm-core/nm-setting-ip4-config.c b/libnm-core/nm-setting-ip4-config.c
146a1d
index 0b8dc89b3..7ffefc25b 100644
146a1d
--- a/libnm-core/nm-setting-ip4-config.c
146a1d
+++ b/libnm-core/nm-setting-ip4-config.c
146a1d
@@ -227,51 +227,9 @@ verify (NMSetting *setting, NMConnection *connection, GError **error)
146a1d
 		return FALSE;
146a1d
 	}
146a1d
 
146a1d
-	if (priv->dhcp_vendor_class_identifier) {
146a1d
-		const char *  bin;
146a1d
-		gsize         unescaped_len;
146a1d
-		gs_free char *to_free = NULL;
146a1d
-
146a1d
-		if (priv->dhcp_vendor_class_identifier[0] == '\0') {
146a1d
-			g_set_error_literal (error,
146a1d
-			                     NM_CONNECTION_ERROR,
146a1d
-			                     NM_CONNECTION_ERROR_INVALID_PROPERTY,
146a1d
-			                     _ ("property cannot be an empty string"));
146a1d
-			g_prefix_error (error,
146a1d
-			                "%s.%s: ",
146a1d
-			                NM_SETTING_IP4_CONFIG_SETTING_NAME,
146a1d
-			                NM_SETTING_IP4_CONFIG_DHCP_VENDOR_CLASS_IDENTIFIER);
146a1d
-			return FALSE;
146a1d
-		}
146a1d
-
146a1d
-		bin = nm_utils_buf_utf8safe_unescape (priv->dhcp_vendor_class_identifier,
146a1d
-		                                      NM_UTILS_STR_UTF8_SAFE_FLAG_NONE,
146a1d
-		                                      &unescaped_len,
146a1d
-		                                      (gpointer *) &to_free);
146a1d
-		/* a DHCP option cannot be longer than 255 bytes */
146a1d
-		if (unescaped_len > 255) {
146a1d
-			g_set_error_literal (error,
146a1d
-			                     NM_CONNECTION_ERROR,
146a1d
-			                     NM_CONNECTION_ERROR_INVALID_PROPERTY,
146a1d
-			                     _ ("property cannot be longer than 255 bytes"));
146a1d
-			g_prefix_error (error,
146a1d
-			                "%s.%s: ",
146a1d
-			                NM_SETTING_IP4_CONFIG_SETTING_NAME,
146a1d
-			                NM_SETTING_IP4_CONFIG_DHCP_VENDOR_CLASS_IDENTIFIER);
146a1d
-			return FALSE;
146a1d
-		}
146a1d
-		if (strlen (bin) != unescaped_len) {
146a1d
-			g_set_error_literal (error,
146a1d
-			                     NM_CONNECTION_ERROR,
146a1d
-			                     NM_CONNECTION_ERROR_INVALID_PROPERTY,
146a1d
-			                     _ ("property cannot contain any nul bytes"));
146a1d
-			g_prefix_error (error,
146a1d
-			                "%s.%s: ",
146a1d
-			                NM_SETTING_IP4_CONFIG_SETTING_NAME,
146a1d
-			                NM_SETTING_IP4_CONFIG_DHCP_VENDOR_CLASS_IDENTIFIER);
146a1d
-			return FALSE;
146a1d
-		}
146a1d
-	}
146a1d
+	if (   priv->dhcp_vendor_class_identifier
146a1d
+	    && !nm_utils_validate_dhcp4_vendor_class_id (priv->dhcp_vendor_class_identifier, error))
146a1d
+		return FALSE;
146a1d
 
146a1d
 	/* Failures from here on are NORMALIZABLE_ERROR... */
146a1d
 
146a1d
diff --git a/po/POTFILES.in b/po/POTFILES.in
146a1d
index 25cb5c4a6..ea2eafa3f 100644
146a1d
--- a/po/POTFILES.in
146a1d
+++ b/po/POTFILES.in
146a1d
@@ -59,6 +59,7 @@ libnm-core/nm-dbus-utils.c
146a1d
 libnm-core/nm-keyfile/nm-keyfile-utils.c
146a1d
 libnm-core/nm-keyfile/nm-keyfile.c
146a1d
 libnm-core/nm-libnm-core-aux/nm-libnm-core-aux.c
146a1d
+libnm-core/nm-libnm-core-intern/nm-libnm-core-utils.c
146a1d
 libnm-core/nm-setting-6lowpan.c
146a1d
 libnm-core/nm-setting-8021x.c
146a1d
 libnm-core/nm-setting-adsl.c
146a1d
diff --git a/src/devices/nm-device.c b/src/devices/nm-device.c
146a1d
index 72a2b1008..012af4d9a 100644
146a1d
--- a/src/devices/nm-device.c
146a1d
+++ b/src/devices/nm-device.c
146a1d
@@ -8754,7 +8754,6 @@ dhcp4_get_vendor_class_identifier (NMDevice *self, NMSettingIP4Config *s_ip4)
146a1d
 {
146a1d
 	gs_free char *config_data_prop = NULL;
146a1d
 	gs_free char *to_free = NULL;
146a1d
-	gboolean validate = FALSE;
146a1d
 	const char *conn_prop;
146a1d
 	GBytes *bytes = NULL;
146a1d
 	const char *bin;
146a1d
@@ -8764,12 +8763,14 @@ dhcp4_get_vendor_class_identifier (NMDevice *self, NMSettingIP4Config *s_ip4)
146a1d
 
146a1d
 	if (!conn_prop) {
146a1d
 		/* set in NetworkManager.conf ? */
146a1d
-		validate = TRUE;
146a1d
 		config_data_prop = nm_config_data_get_connection_default (
146a1d
 		    NM_CONFIG_GET_DATA,
146a1d
 		    NM_CON_DEFAULT ("ipv4.dhcp-vendor-class-identifier"),
146a1d
 		    self);
146a1d
-		conn_prop = config_data_prop;
146a1d
+
146a1d
+		if (   config_data_prop
146a1d
+		    && nm_utils_validate_dhcp4_vendor_class_id (config_data_prop, NULL))
146a1d
+			conn_prop = config_data_prop;
146a1d
 	}
146a1d
 
146a1d
 	if (conn_prop) {
146a1d
@@ -8777,10 +8778,6 @@ dhcp4_get_vendor_class_identifier (NMDevice *self, NMSettingIP4Config *s_ip4)
146a1d
 		                                      NM_UTILS_STR_UTF8_SAFE_FLAG_NONE,
146a1d
 		                                      &len,
146a1d
 		                                      (gpointer *) &to_free);
146a1d
-
146a1d
-		if (validate && (bin[0] == '\0' || len > 255 || strlen (bin) != len))
146a1d
-			return NULL;
146a1d
-
146a1d
 		if (to_free)
146a1d
 			bytes = g_bytes_new_take (g_steal_pointer (&to_free), len);
146a1d
 		else
146a1d
-- 
146a1d
2.26.2
146a1d
146a1d
146a1d
From a491bad06f7c29b257fd948f2149ef80b179da22 Mon Sep 17 00:00:00 2001
146a1d
From: Antonio Cardace <acardace@redhat.com>
146a1d
Date: Thu, 27 Aug 2020 17:43:54 +0200
146a1d
Subject: [PATCH 2/4] initrd: parse 'rd.net.dhcp.vendor-class' kernel cmdline
146a1d
 arg
146a1d
146a1d
This arguments makes NM set the ipv4.dhcp-vendor-class-identifier
146a1d
property for all connections.
146a1d
146a1d
https://bugzilla.redhat.com/show_bug.cgi?id=1872299
146a1d
146a1d
Signed-off-by: Antonio Cardace <acardace@redhat.com>
146a1d
(cherry picked from commit c056cb9306be29a2c194a308b3b6cc639980abe2)
146a1d
(cherry picked from commit 15856a4fa20feaae6bd073fc2874180b2a1a335d)
146a1d
---
146a1d
 src/initrd/nmi-cmdline-reader.c        |  6 ++++
146a1d
 src/initrd/tests/test-cmdline-reader.c | 47 ++++++++++++++++++++++++++
146a1d
 2 files changed, 53 insertions(+)
146a1d
146a1d
diff --git a/src/initrd/nmi-cmdline-reader.c b/src/initrd/nmi-cmdline-reader.c
146a1d
index be39ef896..ba747b30a 100644
146a1d
--- a/src/initrd/nmi-cmdline-reader.c
146a1d
+++ b/src/initrd/nmi-cmdline-reader.c
146a1d
@@ -28,6 +28,7 @@ typedef struct {
146a1d
 	/* Parameters to be set for all connections */
146a1d
 	gboolean ignore_auto_dns;
146a1d
 	int dhcp_timeout;
146a1d
+	char *dhcp4_vci;
146a1d
 } Reader;
146a1d
 
146a1d
 static Reader *
146a1d
@@ -52,6 +53,7 @@ reader_destroy (Reader *reader, gboolean free_hash)
146a1d
 	g_ptr_array_unref (reader->array);
146a1d
 	hash = g_steal_pointer (&reader->hash);
146a1d
 	nm_clear_g_free (&reader->hostname);
146a1d
+	nm_clear_g_free (&reader->dhcp4_vci);
146a1d
 	nm_g_slice_free (reader);
146a1d
 	if (!free_hash)
146a1d
 		return g_steal_pointer (&hash);
146a1d
@@ -95,6 +97,7 @@ reader_create_connection (Reader *reader,
146a1d
 	              NM_SETTING_IP_CONFIG_MAY_FAIL, TRUE,
146a1d
 	              NM_SETTING_IP_CONFIG_IGNORE_AUTO_DNS, reader->ignore_auto_dns,
146a1d
 	              NM_SETTING_IP_CONFIG_DHCP_TIMEOUT, reader->dhcp_timeout,
146a1d
+	              NM_SETTING_IP4_CONFIG_DHCP_VENDOR_CLASS_IDENTIFIER, reader->dhcp4_vci,
146a1d
 	              NULL);
146a1d
 
146a1d
 	setting = nm_setting_ip6_config_new ();
146a1d
@@ -927,6 +930,9 @@ nmi_cmdline_reader_parse (const char *sysfs_dir, const char *const*argv, char **
146a1d
 		else if (nm_streq (tag, "rd.net.timeout.dhcp")) {
146a1d
 			reader->dhcp_timeout = _nm_utils_ascii_str_to_int64 (argument,
146a1d
 			                                                     10, 0, G_MAXINT32, 0);
146a1d
+		} else if (nm_streq (tag, "rd.net.dhcp.vendor-class")) {
146a1d
+			if (nm_utils_validate_dhcp4_vendor_class_id (argument, NULL))
146a1d
+				nm_utils_strdup_reset (&reader->dhcp4_vci, argument);
146a1d
 		}
146a1d
 	}
146a1d
 
146a1d
diff --git a/src/initrd/tests/test-cmdline-reader.c b/src/initrd/tests/test-cmdline-reader.c
146a1d
index 7787cf5ea..a909bc380 100644
146a1d
--- a/src/initrd/tests/test-cmdline-reader.c
146a1d
+++ b/src/initrd/tests/test-cmdline-reader.c
146a1d
@@ -1485,6 +1485,52 @@ test_bootif_off (void)
146a1d
 	g_assert_cmpstr (hostname, ==, NULL);
146a1d
 }
146a1d
 
146a1d
+static void
146a1d
+test_dhcp_vendor_class_id (void)
146a1d
+{
146a1d
+	gs_unref_hashtable GHashTable *connections = NULL;
146a1d
+	const char *const*ARGV = NM_MAKE_STRV ("rd.net.dhcp.vendor-class=testvci",
146a1d
+	                                       "ip=eno1:dhcp");
146a1d
+	NMConnection *connection;
146a1d
+	NMSettingIP4Config *s_ip4;
146a1d
+	gs_free char *hostname = NULL;
146a1d
+	gs_free char *vci_long = NULL;
146a1d
+	char vci_arg_long[512] = {0};
146a1d
+
146a1d
+	connections = nmi_cmdline_reader_parse (TEST_INITRD_DIR "/sysfs", ARGV, &hostname);
146a1d
+	g_assert (connections);
146a1d
+	g_assert_cmpint (g_hash_table_size (connections), ==, 1);
146a1d
+	g_assert_cmpstr (hostname, ==, NULL);
146a1d
+
146a1d
+	connection = g_hash_table_lookup (connections, "eno1");
146a1d
+	g_assert (connection);
146a1d
+	nmtst_assert_connection_verifies_without_normalization (connection);
146a1d
+	s_ip4 = NM_SETTING_IP4_CONFIG (nm_connection_get_setting_ip4_config (connection));
146a1d
+	g_assert_cmpstr (nm_setting_ip4_config_get_dhcp_vendor_class_identifier (s_ip4), ==, "testvci");
146a1d
+
146a1d
+	ARGV = NM_MAKE_STRV ("rd.net.dhcp.vendor-class",
146a1d
+	                     "ip=eno1:dhcp");
146a1d
+	connections = nmi_cmdline_reader_parse (TEST_INITRD_DIR "/sysfs", ARGV, &hostname);
146a1d
+	connection = g_hash_table_lookup (connections, "eno1");
146a1d
+	g_assert (connection);
146a1d
+	nmtst_assert_connection_verifies_without_normalization (connection);
146a1d
+	s_ip4 = NM_SETTING_IP4_CONFIG (nm_connection_get_setting_ip4_config (connection));
146a1d
+	g_assert (nm_setting_ip4_config_get_dhcp_vendor_class_identifier (s_ip4) == NULL);
146a1d
+
146a1d
+
146a1d
+
146a1d
+	memset (vci_arg_long, 'A', 400);
146a1d
+	vci_long = g_strdup_printf ("rd.net.dhcp.vendor-class=%s", vci_arg_long);
146a1d
+	ARGV = NM_MAKE_STRV (vci_long,
146a1d
+	                     "ip=eno1:dhcp");
146a1d
+	connections = nmi_cmdline_reader_parse (TEST_INITRD_DIR "/sysfs", ARGV, &hostname);
146a1d
+	connection = g_hash_table_lookup (connections, "eno1");
146a1d
+	g_assert (connection);
146a1d
+	nmtst_assert_connection_verifies_without_normalization (connection);
146a1d
+	s_ip4 = NM_SETTING_IP4_CONFIG (nm_connection_get_setting_ip4_config (connection));
146a1d
+	g_assert (nm_setting_ip4_config_get_dhcp_vendor_class_identifier (s_ip4) == NULL);
146a1d
+}
146a1d
+
146a1d
 NMTST_DEFINE ();
146a1d
 
146a1d
 int main (int argc, char **argv)
146a1d
@@ -1521,6 +1567,7 @@ int main (int argc, char **argv)
146a1d
 	g_test_add_func ("/initrd/cmdline/bootif/hwtype", test_bootif_hwtype);
146a1d
 	g_test_add_func ("/initrd/cmdline/bootif/off", test_bootif_off);
146a1d
 	g_test_add_func ("/initrd/cmdline/neednet", test_neednet);
146a1d
+	g_test_add_func ("/initrd/cmdline/dhcp/vendor_class_id", test_dhcp_vendor_class_id);
146a1d
 
146a1d
 	return g_test_run ();
146a1d
 }
146a1d
-- 
146a1d
2.26.2
146a1d
146a1d
146a1d
From bbd77df8ae1cc2510b1ff2c1c27ddf3d907faec3 Mon Sep 17 00:00:00 2001
146a1d
From: Antonio Cardace <acardace@redhat.com>
146a1d
Date: Tue, 1 Sep 2020 18:38:45 +0200
146a1d
Subject: [PATCH 3/4] initrd: fix memory leak
146a1d
146a1d
Signed-off-by: Antonio Cardace <acardace@redhat.com>
146a1d
Fixes: 9f9609555d1c ('initrd: add configuration generator')
146a1d
(cherry picked from commit d5c05d07c7aff317284d2d5197d75e0f605b4364)
146a1d
(cherry picked from commit bba54613eb4255166c921844e8b6d2a2bd0000a1)
146a1d
---
146a1d
 shared/nm-glib-aux/nm-macros-internal.h | 8 ++++++++
146a1d
 src/initrd/nm-initrd-generator.c        | 2 +-
146a1d
 2 files changed, 9 insertions(+), 1 deletion(-)
146a1d
146a1d
diff --git a/shared/nm-glib-aux/nm-macros-internal.h b/shared/nm-glib-aux/nm-macros-internal.h
146a1d
index 15bcd7e58..57ddee050 100644
146a1d
--- a/shared/nm-glib-aux/nm-macros-internal.h
146a1d
+++ b/shared/nm-glib-aux/nm-macros-internal.h
146a1d
@@ -216,6 +216,14 @@ NM_AUTO_DEFINE_FCN0 (GError *, gs_local_free_error, g_error_free)
146a1d
 #define gs_unref_keyfile nm_auto(gs_local_keyfile_unref)
146a1d
 NM_AUTO_DEFINE_FCN0 (GKeyFile *, gs_local_keyfile_unref, g_key_file_unref)
146a1d
 
146a1d
+/**
146a1d
+ * gs_free_option_context:
146a1d
+ *
146a1d
+ * Call g_option_context_free() on a variable location when it goes out of scope.
146a1d
+ */
146a1d
+#define gs_free_option_context nm_auto(gs_local_option_context)
146a1d
+NM_AUTO_DEFINE_FCN0 (GOptionContext *, gs_local_option_context, g_option_context_free);
146a1d
+
146a1d
 /*****************************************************************************/
146a1d
 
146a1d
 #include "nm-glib.h"
146a1d
diff --git a/src/initrd/nm-initrd-generator.c b/src/initrd/nm-initrd-generator.c
146a1d
index f984ed739..5a93480bf 100644
146a1d
--- a/src/initrd/nm-initrd-generator.c
146a1d
+++ b/src/initrd/nm-initrd-generator.c
146a1d
@@ -83,7 +83,7 @@ main (int argc, char *argv[])
146a1d
 		{ G_OPTION_REMAINING, '\0', 0, G_OPTION_ARG_STRING_ARRAY, &remaining,       NULL,                                  NULL },
146a1d
 		{ NULL }
146a1d
 	};
146a1d
-	GOptionContext *option_context;
146a1d
+	gs_free_option_context GOptionContext *option_context = NULL;
146a1d
 	gs_free_error GError *error = NULL;
146a1d
 	gs_free char *hostname = NULL;
146a1d
 	int errsv;
146a1d
-- 
146a1d
2.26.2
146a1d
146a1d
146a1d
From 3dec958f413a4566e97183a522afb27b47a9146e Mon Sep 17 00:00:00 2001
146a1d
From: Thomas Haller <thaller@redhat.com>
146a1d
Date: Thu, 3 Sep 2020 11:35:40 +0200
146a1d
Subject: [PATCH 4/4] initrd/tests: fix memleak in test_dhcp_vendor_class_id()
146a1d
146a1d
Having leaks in the tests, breaks running the test under valgrind. There
146a1d
must be no leaks.
146a1d
146a1d
Fixes: c056cb9306be ('initrd: parse 'rd.net.dhcp.vendor-class' kernel cmdline arg')
146a1d
(cherry picked from commit bff23d15d41a42c7b5f43cb3d18d66e7cd289823)
146a1d
(cherry picked from commit 5bea8db7ca8fd7520fe605b59e29b974e04b4721)
146a1d
Signed-off-by: Antonio Cardace <acardace@redhat.com>
146a1d
---
146a1d
 src/initrd/tests/test-cmdline-reader.c | 4 +++-
146a1d
 1 file changed, 3 insertions(+), 1 deletion(-)
146a1d
146a1d
diff --git a/src/initrd/tests/test-cmdline-reader.c b/src/initrd/tests/test-cmdline-reader.c
146a1d
index a909bc380..a11b76e01 100644
146a1d
--- a/src/initrd/tests/test-cmdline-reader.c
146a1d
+++ b/src/initrd/tests/test-cmdline-reader.c
146a1d
@@ -1508,6 +1508,8 @@ test_dhcp_vendor_class_id (void)
146a1d
 	s_ip4 = NM_SETTING_IP4_CONFIG (nm_connection_get_setting_ip4_config (connection));
146a1d
 	g_assert_cmpstr (nm_setting_ip4_config_get_dhcp_vendor_class_identifier (s_ip4), ==, "testvci");
146a1d
 
146a1d
+	nm_clear_pointer (&connections, g_hash_table_unref);
146a1d
+
146a1d
 	ARGV = NM_MAKE_STRV ("rd.net.dhcp.vendor-class",
146a1d
 	                     "ip=eno1:dhcp");
146a1d
 	connections = nmi_cmdline_reader_parse (TEST_INITRD_DIR "/sysfs", ARGV, &hostname);
146a1d
@@ -1517,7 +1519,7 @@ test_dhcp_vendor_class_id (void)
146a1d
 	s_ip4 = NM_SETTING_IP4_CONFIG (nm_connection_get_setting_ip4_config (connection));
146a1d
 	g_assert (nm_setting_ip4_config_get_dhcp_vendor_class_identifier (s_ip4) == NULL);
146a1d
 
146a1d
-
146a1d
+	nm_clear_pointer (&connections, g_hash_table_unref);
146a1d
 
146a1d
 	memset (vci_arg_long, 'A', 400);
146a1d
 	vci_long = g_strdup_printf ("rd.net.dhcp.vendor-class=%s", vci_arg_long);
146a1d
-- 
146a1d
2.26.2
146a1d