nm: Fix double-free of IKE config in error cases and some leaks and potential NULL dereferences

This commit is contained in:
Tobias Brunner
2026-07-24 08:47:38 +02:00
parent bde21aa4f9
commit ad7d50f846
+9 -5
View File
@@ -107,6 +107,7 @@ static GVariant* handler_to_variant(nm_handler_t *handler, char *variant_type,
configuration_attribute_type_t type) configuration_attribute_type_t type)
{ {
GVariantBuilder builder; GVariantBuilder builder;
GVariant *variant;
enumerator_t *enumerator; enumerator_t *enumerator;
chunk_t *chunk; chunk_t *chunk;
@@ -115,7 +116,11 @@ static GVariant* handler_to_variant(nm_handler_t *handler, char *variant_type,
enumerator = handler->create_enumerator(handler, type); enumerator = handler->create_enumerator(handler, type);
while (enumerator->enumerate(enumerator, &chunk)) while (enumerator->enumerate(enumerator, &chunk))
{ {
g_variant_builder_add_value (&builder, addr_to_variant(*chunk)); variant = addr_to_variant(*chunk);
if (variant)
{
g_variant_builder_add_value (&builder, variant);
}
} }
enumerator->destroy(enumerator); enumerator->destroy(enumerator);
@@ -516,6 +521,7 @@ static chunk_t read_safe_file(NMStrongswanPluginPrivate *priv,
NM_VPN_PLUGIN_ERROR_BAD_ARGUMENTS, NM_VPN_PLUGIN_ERROR_BAD_ARGUMENTS,
"Unable to open '%s': %s", safe_path, strerror(errno)); "Unable to open '%s': %s", safe_path, strerror(errno));
} }
g_free(safe_path);
} }
return chunk; return chunk;
} }
@@ -665,6 +671,7 @@ static bool add_auth_cfg_cert(NMStrongswanPluginPrivate *priv,
safe_file = read_safe_file(priv, str, user, err); safe_file = read_safe_file(priv, str, user, err);
if (!safe_file.ptr) if (!safe_file.ptr)
{ {
DESTROY_IF(cert);
return FALSE; return FALSE;
} }
private = lib->creds->create(lib->creds, CRED_PRIVATE_KEY, private = lib->creds->create(lib->creds, CRED_PRIVATE_KEY,
@@ -763,7 +770,7 @@ static bool add_auth_cfg_pw(NMStrongswanPluginPrivate *priv,
str = nm_setting_vpn_get_secret(vpn, "password"); str = nm_setting_vpn_get_secret(vpn, "password");
if (streq(method, "psk")) if (streq(method, "psk"))
{ {
if (strlen(str) < 20) if (!str || strlen(str) < 20)
{ {
g_set_error(err, NM_VPN_PLUGIN_ERROR, g_set_error(err, NM_VPN_PLUGIN_ERROR,
NM_VPN_PLUGIN_ERROR_BAD_ARGUMENTS, NM_VPN_PLUGIN_ERROR_BAD_ARGUMENTS,
@@ -1032,7 +1039,6 @@ static gboolean connect_(NMVpnServicePlugin *plugin, NMConnection *connection,
if (!add_auth_cfg_cert(priv, vpn, peer_cfg, user, err)) if (!add_auth_cfg_cert(priv, vpn, peer_cfg, user, err))
{ {
peer_cfg->destroy(peer_cfg); peer_cfg->destroy(peer_cfg);
ike_cfg->destroy(ike_cfg);
gateway->destroy(gateway); gateway->destroy(gateway);
return FALSE; return FALSE;
} }
@@ -1043,7 +1049,6 @@ static gboolean connect_(NMVpnServicePlugin *plugin, NMConnection *connection,
if (!add_auth_cfg_pw(priv, vpn, peer_cfg, err)) if (!add_auth_cfg_pw(priv, vpn, peer_cfg, err))
{ {
peer_cfg->destroy(peer_cfg); peer_cfg->destroy(peer_cfg);
ike_cfg->destroy(ike_cfg);
gateway->destroy(gateway); gateway->destroy(gateway);
return FALSE; return FALSE;
} }
@@ -1053,7 +1058,6 @@ static gboolean connect_(NMVpnServicePlugin *plugin, NMConnection *connection,
g_set_error(err, NM_VPN_PLUGIN_ERROR, NM_VPN_PLUGIN_ERROR_BAD_ARGUMENTS, g_set_error(err, NM_VPN_PLUGIN_ERROR, NM_VPN_PLUGIN_ERROR_BAD_ARGUMENTS,
"Configuration parameters missing."); "Configuration parameters missing.");
peer_cfg->destroy(peer_cfg); peer_cfg->destroy(peer_cfg);
ike_cfg->destroy(ike_cfg);
gateway->destroy(gateway); gateway->destroy(gateway);
return FALSE; return FALSE;
} }