initrd: avoid assertion inparse_rd_znet() and cleanup

- nm_setting_wired_add_s390_option() asserts that a "value" argument
  is given. Check that the string contains a '=' where we can split.

- pass the requested NM_SETTING_WIRED_SETTING_NAME type to get_conn().
  Otherwise, @s_wired might be %NULL, resulting in an assertion.
  I do wonder whether this always retrieves a connection of the
  appropriate type for modification, or whether a profile could
  be returned that was created for a different purpose. But that
  isn't changed.

- avoid "g_strcmp0 (nettype, "ctc") != 0". I find it unexpected, that we add the
  3rd subchannel component, if the nettype is "ctc" (intuitively, I'd expect it
  to be the opposite). The reasons for this are not documented, but I
  presume it is correct.
  Anyway, using streq() makes this slightly more clear to me, as with
  strcmp() I would wonder whether this was just a typo while with
  streq() I'd be more confident that this is indeed intended.

- don't initialize local variables unnecessarily. The compiler would
  warn if we would forget about this. Also, don'\''t use { } for a
  one-line block.
This commit is contained in:
Thomas Haller
2019-09-27 07:58:58 +02:00
parent df07539105
commit 783fe28465

View File

@@ -686,20 +686,19 @@ parse_rd_peerdns (GHashTable *connections, char *argument)
static void static void
parse_rd_znet (GHashTable *connections, char *argument) parse_rd_znet (GHashTable *connections, char *argument)
{ {
const char *nettype = NULL; const char *nettype;
const char *tmp = NULL;
const char *subchannels[4] = { 0, 0, 0, 0 }; const char *subchannels[4] = { 0, 0, 0, 0 };
const char *tmp;
NMConnection *connection; NMConnection *connection;
NMSettingWired *s_wired = NULL; NMSettingWired *s_wired;
nettype = get_word (&argument, ','); nettype = get_word (&argument, ',');
subchannels[0] = get_word (&argument, ','); subchannels[0] = get_word (&argument, ',');
subchannels[1] = get_word (&argument, ','); subchannels[1] = get_word (&argument, ',');
if (g_strcmp0 (nettype, "ctc") != 0) { if (!nm_streq0 (nettype, "ctc"))
subchannels[2] = get_word (&argument, ','); subchannels[2] = get_word (&argument, ',');
}
connection = get_conn (connections, NULL, NULL); connection = get_conn (connections, NULL, NM_SETTING_WIRED_SETTING_NAME);
s_wired = nm_connection_get_setting_wired (connection); s_wired = nm_connection_get_setting_wired (connection);
g_object_set (s_wired, g_object_set (s_wired,
NM_SETTING_WIRED_S390_NETTYPE, nettype, NM_SETTING_WIRED_S390_NETTYPE, nettype,
@@ -707,10 +706,17 @@ parse_rd_znet (GHashTable *connections, char *argument)
NULL); NULL);
while ((tmp = get_word (&argument, ',')) != NULL) { while ((tmp = get_word (&argument, ',')) != NULL) {
gs_strfreev char ** optval = NULL; char *val;
optval = g_strsplit (tmp, "=", 2); val = strchr (tmp, '=');
nm_setting_wired_add_s390_option (s_wired, optval[0], optval[1]); if (val) {
gs_free char *key = NULL;
key = g_strndup (tmp, val - tmp);
val[0] = '\0';
val++;
nm_setting_wired_add_s390_option (s_wired, key, val);
}
} }
} }