Blame SOURCES/1001-initrd-fix-BOOTIF-generation-rh1853277.patch

b35f49
From 84cd78aee89120953e703dde308d850ddaadbfc4 Mon Sep 17 00:00:00 2001
b35f49
From: Beniamino Galvani <bgalvani@redhat.com>
b35f49
Date: Fri, 3 Jul 2020 15:26:28 +0200
b35f49
Subject: [PATCH] initrd: fix generating default BOOTIF= connection
b35f49
b35f49
There is a bug when parsing a BOOTIF= without any existing
b35f49
connection. The generated connection doesn't have wired setting and
b35f49
later we try to access it:
b35f49
b35f49
 # nm-initrd-generator --stdout -- BOOTIF=01-50-50-00-9f-21-21
b35f49
  (nm-initrd-generator:1546): libnm-CRITICAL **: ((libnm-core/nm-setting-wired.c:205)): assertion '<dropped>' failed
b35f49
  (nm-initrd-generator:1546): GLib-GObject-CRITICAL **: g_object_set: assertion 'G_IS_OBJECT (object)' failed
b35f49
b35f49
Fix this.
b35f49
b35f49
https://bugzilla.redhat.com/show_bug.cgi?id=1853277
b35f49
b35f49
Fixes: 25a2b6e14ff5 ('initrd: rework command line parsing')
b35f49
(cherry picked from commit 3023c70e4e1e50ddf5e7dae727fc3d67bfa18b32)
b35f49
(cherry picked from commit b8246ea367a0041cb1527a08f47247877a4c07bd)
b35f49
---
b35f49
 src/initrd/nmi-cmdline-reader.c        |  1 +
b35f49
 src/initrd/tests/test-cmdline-reader.c | 41 ++++++++++++++++++++++++--
b35f49
 2 files changed, 40 insertions(+), 2 deletions(-)
b35f49
b35f49
diff --git a/src/initrd/nmi-cmdline-reader.c b/src/initrd/nmi-cmdline-reader.c
b35f49
index 69e5e56d0..418e837d8 100644
b35f49
--- a/src/initrd/nmi-cmdline-reader.c
b35f49
+++ b/src/initrd/nmi-cmdline-reader.c
b35f49
@@ -132,6 +132,7 @@ reader_get_default_connection (Reader *reader)
b35f49
 		                                NULL,
b35f49
 		                                NM_SETTING_WIRED_SETTING_NAME,
b35f49
 		                                NM_CONNECTION_MULTI_CONNECT_MULTIPLE);
b35f49
+		nm_connection_add_setting (con, nm_setting_wired_new ());
b35f49
 		reader->default_connection = con;
b35f49
 	}
b35f49
 	return reader->default_connection;
b35f49
diff --git a/src/initrd/tests/test-cmdline-reader.c b/src/initrd/tests/test-cmdline-reader.c
b35f49
index 110770554..b25f49e22 100644
b35f49
--- a/src/initrd/tests/test-cmdline-reader.c
b35f49
+++ b/src/initrd/tests/test-cmdline-reader.c
b35f49
@@ -1064,7 +1064,7 @@ test_rd_znet_no_ip (void)
b35f49
 }
b35f49
 
b35f49
 static void
b35f49
-test_bootif (void)
b35f49
+test_bootif_ip (void)
b35f49
 {
b35f49
 	gs_unref_hashtable GHashTable *connections = NULL;
b35f49
 	const char *const*ARGV = NM_MAKE_STRV ("BOOTIF=00:53:AB:cd:02:03",
b35f49
@@ -1101,6 +1101,42 @@ test_bootif (void)
b35f49
 	g_assert (!nm_setting_ip_config_get_ignore_auto_dns (s_ip6));
b35f49
 }
b35f49
 
b35f49
+static void
b35f49
+test_bootif_no_ip (void)
b35f49
+{
b35f49
+	gs_unref_hashtable GHashTable *connections = NULL;
b35f49
+	const char *const*ARGV = NM_MAKE_STRV ("BOOTIF=00:53:AB:cd:02:03");
b35f49
+	NMConnection *connection;
b35f49
+	NMSettingWired *s_wired;
b35f49
+	NMSettingIPConfig *s_ip4;
b35f49
+	NMSettingIPConfig *s_ip6;
b35f49
+	gs_free char *hostname = NULL;
b35f49
+
b35f49
+	connections = nmi_cmdline_reader_parse (TEST_INITRD_DIR "/sysfs", ARGV, &hostname);
b35f49
+	g_assert (connections);
b35f49
+	g_assert_cmpint (g_hash_table_size (connections), ==, 1);
b35f49
+	g_assert_cmpstr (hostname, ==, NULL);
b35f49
+
b35f49
+	connection = g_hash_table_lookup (connections, "default_connection");
b35f49
+	g_assert (connection);
b35f49
+	nmtst_assert_connection_verifies_without_normalization (connection);
b35f49
+	g_assert_cmpstr (nm_connection_get_id (connection), ==, "Wired Connection");
b35f49
+
b35f49
+	s_wired = nm_connection_get_setting_wired (connection);
b35f49
+	g_assert_cmpstr (nm_setting_wired_get_mac_address (s_wired), ==, "00:53:AB:CD:02:03");
b35f49
+	g_assert (s_wired);
b35f49
+
b35f49
+	s_ip4 = nm_connection_get_setting_ip4_config (connection);
b35f49
+	g_assert (s_ip4);
b35f49
+	g_assert_cmpstr (nm_setting_ip_config_get_method (s_ip4), ==, NM_SETTING_IP4_CONFIG_METHOD_AUTO);
b35f49
+	g_assert (nm_setting_ip_config_get_may_fail (s_ip4));
b35f49
+
b35f49
+	s_ip6 = nm_connection_get_setting_ip6_config (connection);
b35f49
+	g_assert (s_ip6);
b35f49
+	g_assert_cmpstr (nm_setting_ip_config_get_method (s_ip6), ==, NM_SETTING_IP6_CONFIG_METHOD_AUTO);
b35f49
+	g_assert (nm_setting_ip_config_get_may_fail (s_ip6));
b35f49
+}
b35f49
+
b35f49
 static void
b35f49
 test_bootif_hwtype (void)
b35f49
 {
b35f49
@@ -1255,7 +1291,8 @@ int main (int argc, char **argv)
b35f49
 	g_test_add_func ("/initrd/cmdline/rd_znet", test_rd_znet);
b35f49
 	g_test_add_func ("/initrd/cmdline/rd_znet/legacy", test_rd_znet_legacy);
b35f49
 	g_test_add_func ("/initrd/cmdline/rd_znet/no_ip", test_rd_znet_no_ip);
b35f49
-	g_test_add_func ("/initrd/cmdline/bootif", test_bootif);
b35f49
+	g_test_add_func ("/initrd/cmdline/bootif/ip", test_bootif_ip);
b35f49
+	g_test_add_func ("/initrd/cmdline/bootif/no_ip", test_bootif_no_ip);
b35f49
 	g_test_add_func ("/initrd/cmdline/bootif/hwtype", test_bootif_hwtype);
b35f49
 	g_test_add_func ("/initrd/cmdline/bootif/off", test_bootif_off);
b35f49
 
b35f49
-- 
b35f49
2.26.2
b35f49