Blame SOURCES/1005-initrd-fix-crash-parsing-empty-rd.znet-argument.patch

964b59
From 31e882a46229c74649216ddc80fdb2ecbf75ab9e Mon Sep 17 00:00:00 2001
964b59
From: Beniamino Galvani <bgalvani@redhat.com>
964b59
Date: Tue, 16 Mar 2021 10:00:44 +0100
964b59
Subject: [PATCH 1/1] initrd: fix crash parsing empty rd.znet argument
964b59
964b59
Ignore a rd.znet argument without subchannels. When using net.ifnames
964b59
(the default), subchannels are used to build the interface name, which
964b59
is required to match the right connection.
964b59
964b59
With net.ifnames=0 the interface name is build using a prefix and a
964b59
global counter and therefore in theory it is possible to omit
964b59
subchannels. However, without subchannels there won't be a udev rule
964b59
that renames the interface and so it can't work.
964b59
964b59
https://bugzilla.redhat.com/show_bug.cgi?id=1931284
964b59
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/783
964b59
(cherry picked from commit 0f8fe3c76b9ecdf52c1690295f7dcc7b7ade16b6)
964b59
(cherry picked from commit d0d2d97ca51444bc7013943748ede334cc79a33f)
964b59
---
964b59
 src/core/initrd/nmi-cmdline-reader.c        |  5 +++++
964b59
 src/core/initrd/tests/test-cmdline-reader.c | 19 +++++++++++++++++++
964b59
 2 files changed, 24 insertions(+)
964b59
964b59
diff --git a/src/core/initrd/nmi-cmdline-reader.c b/src/core/initrd/nmi-cmdline-reader.c
964b59
index 5f40f63ef269..e3ecc7d969bb 100644
964b59
--- a/src/core/initrd/nmi-cmdline-reader.c
964b59
+++ b/src/core/initrd/nmi-cmdline-reader.c
964b59
@@ -917,6 +917,11 @@ reader_parse_rd_znet(Reader *reader, char *argument, gboolean net_ifnames)
964b59
     subchannels[0] = get_word(&argument, ',');
964b59
     subchannels[1] = get_word(&argument, ',');
964b59
 
964b59
+    /* Without subchannels we can't univocally match
964b59
+     * a device. */
964b59
+    if (!subchannels[0] || !subchannels[1])
964b59
+        return;
964b59
+
964b59
     if (nm_streq0(nettype, "ctc")) {
964b59
         if (net_ifnames == TRUE) {
964b59
             prefix = "sl";
964b59
diff --git a/src/core/initrd/tests/test-cmdline-reader.c b/src/core/initrd/tests/test-cmdline-reader.c
964b59
index 4b450aae0fa4..ba072e7933dc 100644
964b59
--- a/src/core/initrd/tests/test-cmdline-reader.c
964b59
+++ b/src/core/initrd/tests/test-cmdline-reader.c
964b59
@@ -1815,6 +1815,24 @@ test_rd_znet_no_ip(void)
964b59
     g_assert_cmpint(g_hash_table_size(connections), ==, 0);
964b59
 }
964b59
 
964b59
+static void
964b59
+test_rd_znet_malformed(void)
964b59
+{
964b59
+    const char *const *const ARGV0  = NM_MAKE_STRV("rd.znet=");
964b59
+    const char *const *const ARGV1  = NM_MAKE_STRV("rd.znet=,");
964b59
+    const char *const *const ARGV2  = NM_MAKE_STRV("rd.znet=foobar");
964b59
+    const char *const *const ARGV3  = NM_MAKE_STRV("rd.znet=qeth,0.0.0800,,,layer2=0,portno=1");
964b59
+    const char *const *const ARGV[] = {ARGV0, ARGV1, ARGV2, ARGV3};
964b59
+    guint                    i;
964b59
+
964b59
+    for (i = 0; i < G_N_ELEMENTS(ARGV); i++) {
964b59
+        gs_unref_hashtable GHashTable *connections = NULL;
964b59
+
964b59
+        connections = _parse_cons(ARGV[i]);
964b59
+        g_assert_cmpint(g_hash_table_size(connections), ==, 0);
964b59
+    }
964b59
+}
964b59
+
964b59
 static void
964b59
 test_bootif_ip(void)
964b59
 {
964b59
@@ -2173,6 +2191,7 @@ main(int argc, char **argv)
964b59
     g_test_add_func("/initrd/cmdline/rd_znet", test_rd_znet);
964b59
     g_test_add_func("/initrd/cmdline/rd_znet/legacy", test_rd_znet_legacy);
964b59
     g_test_add_func("/initrd/cmdline/rd_znet/no_ip", test_rd_znet_no_ip);
964b59
+    g_test_add_func("/initrd/cmdline/rd_znet/empty", test_rd_znet_malformed);
964b59
     g_test_add_func("/initrd/cmdline/bootif/ip", test_bootif_ip);
964b59
     g_test_add_func("/initrd/cmdline/bootif/no_ip", test_bootif_no_ip);
964b59
     g_test_add_func("/initrd/cmdline/bootif/hwtype", test_bootif_hwtype);
964b59
-- 
964b59
2.30.2
964b59