mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2025-12-25 14:10:08 +01:00
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:
parent
bb132cd6de
commit
c91dfb850e
1 changed files with 16 additions and 14 deletions
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue