summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2019-12-23 08:01:23 +0100
committerThomas Haller <thaller@redhat.com>2019-12-31 02:13:45 +0100
commitcb7cfc3f127cef9f0e19770c6a91bd5b700343ae (patch)
tree29b1fa89382da6663b893943b7042f871a1a305e
parent7d5d7c6d59cf43a02e98adf6192803ce58130e28 (diff)
downloadNetworkManager-cb7cfc3f127cef9f0e19770c6a91bd5b700343ae.tar.gz
shared: don't allow NULL arguments with g_hash_table_steal_extended() compat implementation
We cannot know the key/value free functions, hence, our compat implementation cannot free the values if they are not requested. The "solution" is to require the caller to fetch all values, always.
-rw-r--r--shared/nm-glib-aux/nm-glib.h19
1 files changed, 14 insertions, 5 deletions
diff --git a/shared/nm-glib-aux/nm-glib.h b/shared/nm-glib-aux/nm-glib.h
index e7e69dc5fe..4043ec2240 100644
--- a/shared/nm-glib-aux/nm-glib.h
+++ b/shared/nm-glib-aux/nm-glib.h
@@ -608,21 +608,30 @@ g_hash_table_steal_extended (GHashTable *hash_table,
gpointer *stolen_key,
gpointer *stolen_value)
{
+ g_assert (stolen_key);
+ g_assert (stolen_value);
+
if (g_hash_table_lookup_extended (hash_table, lookup_key, stolen_key, stolen_value)) {
g_hash_table_steal (hash_table, lookup_key);
return TRUE;
}
- if (stolen_key)
- *stolen_key = NULL;
- if (stolen_value)
- *stolen_value = NULL;
+ *stolen_key = NULL;
+ *stolen_value = NULL;
return FALSE;
}
#else
#define g_hash_table_steal_extended(hash_table, lookup_key, stolen_key, stolen_value) \
({ \
+ gpointer *_stolen_key = (stolen_key); \
+ gpointer *_stolen_value = (stolen_value); \
+ \
+ /* we cannot allow NULL arguments, because then we would leak the values in
+ * the compat implementation. */ \
+ g_assert (_stolen_key); \
+ g_assert (_stolen_value); \
+ \
G_GNUC_BEGIN_IGNORE_DEPRECATIONS \
- g_hash_table_steal_extended (hash_table, lookup_key, stolen_key, stolen_value); \
+ g_hash_table_steal_extended (hash_table, lookup_key, _stolen_key, _stolen_value); \
G_GNUC_END_IGNORE_DEPRECATIONS \
})
#endif