diff options
author | Thomas Haller <thaller@redhat.com> | 2018-03-14 10:16:25 +0100 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2018-03-20 15:08:18 +0100 |
commit | c5457fcadb78fb37b4aa4b6307b4b8163acdadcb (patch) | |
tree | b9ecdd8433391c0394d1dda03ef23c781ca7d953 | |
parent | e17cd1d742c47122b159040ce23fbf684b21c486 (diff) | |
download | NetworkManager-c5457fcadb78fb37b4aa4b6307b4b8163acdadcb.tar.gz |
settings: invalidate pointers for debugging use of outdated connections_cached_list
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.c | 22 |
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); |