summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2018-03-14 10:16:25 +0100
committerThomas Haller <thaller@redhat.com>2018-03-18 21:09:56 +0100
commit9197ca2bc8ec2eba42e828921b55b5224b6b2a91 (patch)
treedde83d46ac892811496c2286c43d7a47e5cdb629
parent4737b34d358c68156e7b588b0d39599ef662ec65 (diff)
downloadNetworkManager-th/complete-generic-cleanup.tar.gz
settings: invalidate pointers for debugging use of outdated connections_cached_listth/complete-generic-cleanup
connections_cached_list stays only valid until we remove/add connections to NMSettings. Using the list without cloning requires to be aware of that. When clearing the list, invalidate all pointers, in the hope that a following use-after-free will blow up with an assertion. We only do this in elevated assertion mode. It's not to prevent any bugs, it's to better notice it.
-rw-r--r--src/settings/nm-settings.c22
1 files changed, 19 insertions, 3 deletions
diff --git a/src/settings/nm-settings.c b/src/settings/nm-settings.c
index 7cb5a2234b..ade117de5d 100644
--- a/src/settings/nm-settings.c
+++ b/src/settings/nm-settings.c
@@ -367,6 +367,22 @@ error:
g_dbus_method_invocation_take_error (invocation, error);
}
+static void
+_clear_connections_cached_list (NMSettingsConnection ***p_connections_cached_list)
+{
+#if NM_MORE_ASSERTS
+ /* set the pointer to a bogus value. This makes it more apparent
+ * if somebody has a reference to the cached list and still uses
+ * it. That is a bug, this code just tries to make it blow up
+ * more eagerly. */
+ if (*p_connections_cached_list) {
+ NMSettingsConnection **p = *p_connections_cached_list;
+ memset (p, 0xdeaddead, sizeof (NMSettingsConnection *) * (NM_PTRARRAY_LEN (p) + 1));
+ }
+#endif
+ g_clear_pointer (p_connections_cached_list, g_free);
+}
+
/**
* nm_settings_get_connections:
* @self: the #NMSettings
@@ -865,7 +881,7 @@ connection_removed (NMSettingsConnection *connection, gpointer user_data)
/* Forget about the connection internally */
g_hash_table_remove (priv->connections, (gpointer) cpath);
- g_clear_pointer (&priv->connections_cached_list, g_free);
+ _clear_connections_cached_list (&priv->connections_cached_list);
_emit_connection_removed (self, connection);
@@ -998,7 +1014,7 @@ claim_connection (NMSettings *self, NMSettingsConnection *connection)
g_hash_table_insert (priv->connections,
(gpointer) nm_connection_get_path (NM_CONNECTION (connection)),
g_object_ref (connection));
- g_clear_pointer (&priv->connections_cached_list, g_free);
+ _clear_connections_cached_list (&priv->connections_cached_list);
nm_utils_log_connection_diff (NM_CONNECTION (connection), NULL, LOGL_DEBUG, LOGD_CORE, "new connection", "++ ");
@@ -1953,7 +1969,7 @@ finalize (GObject *object)
NMSettingsPrivate *priv = NM_SETTINGS_GET_PRIVATE (self);
g_hash_table_destroy (priv->connections);
- g_clear_pointer (&priv->connections_cached_list, g_free);
+ _clear_connections_cached_list (&priv->connections_cached_list);
g_slist_free_full (priv->unmanaged_specs, g_free);
g_slist_free_full (priv->unrecognized_specs, g_free);