initrd: fix crash parsing empty rd.znet argument

Ignore a rd.znet argument without subchannels. When using net.ifnames
(the default), subchannels are used to build the interface name, which
is required to match the right connection.

With net.ifnames=0 the interface name is build using a prefix and a
global counter and therefore in theory it is possible to omit
subchannels. However, without subchannels there won't be a udev rule
that renames the interface and so it can't work.

https://bugzilla.redhat.com/show_bug.cgi?id=1931284
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/783
(cherry picked from commit 0f8fe3c76b)
This commit is contained in:
Beniamino Galvani 2021-03-16 10:00:44 +01:00
parent 1bf4c3039a
commit d0d2d97ca5
2 changed files with 24 additions and 0 deletions

View file

@ -930,6 +930,11 @@ reader_parse_rd_znet(Reader *reader, char *argument, gboolean net_ifnames)
subchannels[0] = get_word(&argument, ',');
subchannels[1] = get_word(&argument, ',');
/* Without subchannels we can't univocally match
* a device. */
if (!subchannels[0] || !subchannels[1])
return;
if (nm_streq0(nettype, "ctc")) {
if (net_ifnames == TRUE) {
prefix = "sl";

View file

@ -1855,6 +1855,24 @@ test_rd_znet_no_ip(void)
g_assert_cmpint(g_hash_table_size(connections), ==, 0);
}
static void
test_rd_znet_malformed(void)
{
const char *const *const ARGV0 = NM_MAKE_STRV("rd.znet=");
const char *const *const ARGV1 = NM_MAKE_STRV("rd.znet=,");
const char *const *const ARGV2 = NM_MAKE_STRV("rd.znet=foobar");
const char *const *const ARGV3 = NM_MAKE_STRV("rd.znet=qeth,0.0.0800,,,layer2=0,portno=1");
const char *const *const ARGV[] = {ARGV0, ARGV1, ARGV2, ARGV3};
guint i;
for (i = 0; i < G_N_ELEMENTS(ARGV); i++) {
gs_unref_hashtable GHashTable *connections = NULL;
connections = _parse_cons(ARGV[i]);
g_assert_cmpint(g_hash_table_size(connections), ==, 0);
}
}
static void
test_bootif_ip(void)
{
@ -2190,6 +2208,7 @@ main(int argc, char **argv)
g_test_add_func("/initrd/cmdline/rd_znet", test_rd_znet);
g_test_add_func("/initrd/cmdline/rd_znet/legacy", test_rd_znet_legacy);
g_test_add_func("/initrd/cmdline/rd_znet/no_ip", test_rd_znet_no_ip);
g_test_add_func("/initrd/cmdline/rd_znet/empty", test_rd_znet_malformed);
g_test_add_func("/initrd/cmdline/bootif/ip", test_bootif_ip);
g_test_add_func("/initrd/cmdline/bootif/no_ip", test_bootif_no_ip);
g_test_add_func("/initrd/cmdline/bootif/hwtype", test_bootif_hwtype);