summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2021-03-16 11:37:56 +0100
committerThomas Haller <thaller@redhat.com>2021-03-16 11:58:09 +0100
commitc91dfb850ea1360d462ffdd1d9535b9c6da02ded (patch)
tree1c770fdf953f9e94fa2204b9c7d65fc36e533bbe /src
parentbb132cd6de5299bbe83bf5072c966c706a9dd67b (diff)
downloadNetworkManager-c91dfb850ea1360d462ffdd1d9535b9c6da02ded.tar.gz
initrd: avoid cloning string in reader_parse_rd_znet()th/s390-option-bridge-role
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.
Diffstat (limited to 'src')
-rw-r--r--src/nm-initrd-generator/nmi-cmdline-reader.c30
1 files changed, 16 insertions, 14 deletions
diff --git a/src/nm-initrd-generator/nmi-cmdline-reader.c b/src/nm-initrd-generator/nmi-cmdline-reader.c
index 2f50426d8d..d6b84c2e57 100644
--- a/src/nm-initrd-generator/nmi-cmdline-reader.c
+++ b/src/nm-initrd-generator/nmi-cmdline-reader.c
@@ -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);
}
}