From ce456f5b77ff3ef71247f140b4af2eed98a39617 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 3 Apr 2019 16:02:11 +0200 Subject: [PATCH] all: don't accept %NULL as delimiters for nm_utils_strsplit_set() The caller should make a conscious decision which delimiters to use. Unfortunately, there is a variety of different demiters in use. This should be unitfied and the callers should use one of a few specific set of delimiters. This could be unified by (re)using a define as delimiters, like strv = nm_utils_strsplit_set_full (value, MULTILIST_WITH_ESCAPE_CHARS, NM_UTILS_STRSPLIT_SET_FLAGS_ALLOW_ESCAPING); where MULTILIST_WITH_ESCAPE_CHARS has a particular meaning that should be reused for similar uses. However, leaving the delimiter at NULL is not good because it's unclear who wants that default behavior (and what the default should be). Don't allow that. There are almost no callers that relied on this default anyway. --- shared/nm-utils/nm-shared-utils.c | 7 ++++--- src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-reader.c | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/shared/nm-utils/nm-shared-utils.c b/shared/nm-utils/nm-shared-utils.c index 13a1a35f6e..1554d4cd07 100644 --- a/shared/nm-utils/nm-shared-utils.c +++ b/shared/nm-utils/nm-shared-utils.c @@ -974,8 +974,7 @@ _char_lookup_table_init (guint8 lookup[static 256], /** * nm_utils_strsplit_set_full: * @str: the string to split. - * @delimiters: the set of delimiters. If %NULL, defaults to " \t\n", - * like bash's $IFS. + * @delimiters: the set of delimiters. * @flags: additional flags for controlling the operation. * * This is a replacement for g_strsplit_set() which avoids copying @@ -1017,8 +1016,10 @@ nm_utils_strsplit_set_full (const char *str, return NULL; /* initialize lookup table for delimiter */ - if (!delimiters) + if (!delimiters) { + nm_assert_not_reached (); delimiters = " \t\n"; + } _char_lookup_table_init (delimiters_table, delimiters); diff --git a/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-reader.c b/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-reader.c index 8d39f827ca..93d48dfdd4 100644 --- a/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-reader.c +++ b/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-reader.c @@ -4147,7 +4147,7 @@ parse_ethtool_option (const char *value, gs_free const char **words = NULL; guint i; - words = nm_utils_strsplit_set (value, NULL); + words = nm_utils_strsplit_set (value, " \t\n"); if (!words) return;