summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2020-03-26 12:39:03 +0100
committerThomas Haller <thaller@redhat.com>2020-04-04 19:51:34 +0200
commitf51cf10ccc6dc630def1811a6b2a7e40120d35e6 (patch)
treea0449ebca92e736d99c91a9c88a78ed74f99b8aa
parent05756ddc3a9ee3b10996bc388c5a83aa17458af0 (diff)
downloadNetworkManager-f51cf10ccc6dc630def1811a6b2a7e40120d35e6.tar.gz
libnm: ensure we have no empty data keys in NMSettingVpn
Ensure that the data hash doesn't contain keys with empty key-name. It just doesn't make sense, and will lead to potential problems later, if we would allow this to happen. For example, keyfile writer may naively try to set all keys, without checking for empty keys. That may lead to assertion failures or worse, later on. Don't allow that. Also, assert against non-empty keys in nm_setting_vpn_get_data_item() and nm_setting_vpn_remove_data_item(). This stricter handling is a change in behavior, however it would have always been a bug trying to refer to empty key names. So, this assertion will only help to find those bugs.
-rw-r--r--libnm-core/nm-setting-vpn.c12
1 files changed, 10 insertions, 2 deletions
diff --git a/libnm-core/nm-setting-vpn.c b/libnm-core/nm-setting-vpn.c
index c2aa980a0b..d661204f60 100644
--- a/libnm-core/nm-setting-vpn.c
+++ b/libnm-core/nm-setting-vpn.c
@@ -198,6 +198,7 @@ const char *
nm_setting_vpn_get_data_item (NMSettingVpn *setting, const char *key)
{
g_return_val_if_fail (NM_IS_SETTING_VPN (setting), NULL);
+ g_return_val_if_fail (key && key[0], NULL);
return nm_g_hash_table_lookup (NM_SETTING_VPN_GET_PRIVATE (setting)->data, key);
}
@@ -241,7 +242,7 @@ gboolean
nm_setting_vpn_remove_data_item (NMSettingVpn *setting, const char *key)
{
g_return_val_if_fail (NM_IS_SETTING_VPN (setting), FALSE);
- g_return_val_if_fail (key, FALSE);
+ g_return_val_if_fail (key && key[0], FALSE);
if (nm_g_hash_table_remove (NM_SETTING_VPN_GET_PRIVATE (setting)->data, key)) {
_notify (setting, PROP_DATA);
@@ -1032,8 +1033,15 @@ set_property (GObject *object, guint prop_id,
GHashTable *hash = g_value_get_boxed (value);
if ( hash
- && g_hash_table_size (hash) > 0)
+ && g_hash_table_size (hash) > 0) {
priv->data = _nm_utils_copy_strdict (hash);
+
+ /* empty keys are not allowed. Usually, we would reject them in verify(), but then
+ * our nm_setting_vpn_remove_data_item() also doesn't allow empty keys. So, if we failed
+ * it in verify(), it would be only fixable by setting PROP_DATA again. Instead,
+ * silently drop it. */
+ g_hash_table_remove (priv->data, "");
+ }
}
break;
case PROP_SECRETS: {