initrd: avoid cloning string in reader_parse_rd_znet()

The code did:

   key    = g_strndup(tmp, val - tmp);
   val[0] = '\0';

That is pointless. If we strndup the key, we don't need to truncate
the string at the '='. It might be nicer not to mutate the input string,
however, the entire code with "argument" parsing is about mutating the
input string, so that is something we apparently are fine with.

As such, don't clone the string anymore.
This commit is contained in:
Thomas Haller 2021-03-16 11:37:56 +01:00
parent bb132cd6de
commit c91dfb850e
No known key found for this signature in database
GPG key ID: 29C2366E4DFC5728

View file

@ -969,23 +969,25 @@ reader_parse_rd_znet(Reader *reader, char *argument, gboolean net_ifnames)
NULL);
while ((tmp = get_word(&argument, ',')) != NULL) {
char *val;
const char *key;
char * val;
val = strchr(tmp, '=');
if (val) {
gs_free char *key = NULL;
key = g_strndup(tmp, val - tmp);
val[0] = '\0';
val++;
if (!_nm_setting_wired_is_valid_s390_option(key)
|| !_nm_setting_wired_is_valid_s390_option_value(key, val)) {
/* Invalid setting. Silently ignore, but also ensure we
* didn't already set it. */
nm_setting_wired_remove_s390_option(s_wired, key);
} else
nm_setting_wired_add_s390_option(s_wired, key, val);
if (!val) {
/* an invalid (or empty) entry. Ignore. */
continue;
}
key = tmp;
val[0] = '\0';
val++;
if (!_nm_setting_wired_is_valid_s390_option(key)
|| !_nm_setting_wired_is_valid_s390_option_value(key, val)) {
/* Invalid setting. Silently ignore, but also ensure we
* didn't already set it. */
nm_setting_wired_remove_s390_option(s_wired, key);
} else
nm_setting_wired_add_s390_option(s_wired, key, val);
}
}