From e56f126071882b88f3d6ef53cb611794d12e5e14 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 25 May 2021 21:50:41 +0200 Subject: [PATCH] libnm: fix error handling in NMVpnPluginOld's _connect_generic() Also Coverity found that something is wrong here: Error: FORWARD_NULL (CWE-476): [#def361] NetworkManager-1.31.5/src/libnm-client-impl/nm-vpn-plugin-old.c:441: var_compare_op: Comparing "connection" to null implies that "connection" might be null. NetworkManager-1.31.5/src/libnm-client-impl/nm-vpn-plugin-old.c:489: var_deref_model: Passing null pointer "connection" to "g_object_unref", which dereferences it. # 487| } # 488| # 489|-> g_object_unref(connection); # 490| } # 491| Fixes: 6793a32a8c54 ('libnm: port to GDBus') --- src/libnm-client-impl/nm-vpn-plugin-old.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/libnm-client-impl/nm-vpn-plugin-old.c b/src/libnm-client-impl/nm-vpn-plugin-old.c index be4e1cf292..7430622b90 100644 --- a/src/libnm-client-impl/nm-vpn-plugin-old.c +++ b/src/libnm-client-impl/nm-vpn-plugin-old.c @@ -420,12 +420,12 @@ _connect_generic(NMVpnPluginOld * plugin, GVariant * properties, GVariant * details) { - NMVpnPluginOldPrivate *priv = NM_VPN_PLUGIN_OLD_GET_PRIVATE(plugin); - NMVpnPluginOldClass * vpn_class = NM_VPN_PLUGIN_OLD_GET_CLASS(plugin); - NMConnection * connection; - gboolean success = FALSE; - GError * error = NULL; - guint fail_stop_timeout = 0; + NMVpnPluginOldPrivate *priv = NM_VPN_PLUGIN_OLD_GET_PRIVATE(plugin); + NMVpnPluginOldClass * vpn_class = NM_VPN_PLUGIN_OLD_GET_CLASS(plugin); + gs_unref_object NMConnection *connection = NULL; + gboolean success = FALSE; + GError * error = NULL; + guint fail_stop_timeout = 0; if (priv->state != NM_VPN_SERVICE_STATE_STOPPED && priv->state != NM_VPN_SERVICE_STATE_INIT) { g_dbus_method_invocation_return_error(context, @@ -445,6 +445,7 @@ _connect_generic(NMVpnPluginOld * plugin, "Invalid connection: %s", error->message); g_clear_error(&error); + return; } priv->interactive = FALSE; @@ -485,8 +486,6 @@ _connect_generic(NMVpnPluginOld * plugin, */ schedule_fail_stop(plugin, fail_stop_timeout); } - - g_object_unref(connection); } static void