From b57a3a4cc62e3e74c5c0660834449f967236ee17 Mon Sep 17 00:00:00 2001 From: Beniamino Galvani Date: Mon, 4 Mar 2019 14:24:56 +0100 Subject: [PATCH 1/4] clients: fix double free @secrets is unreferenced at the end of request_secrets_from_ui() and so try_spawn_vpn_auth_helper() must take a reference to it. Fixes: 1a0fc8d437b04641b41c86cd1e9a35c48b5b2c67 --- clients/common/nm-secret-agent-simple.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clients/common/nm-secret-agent-simple.c b/clients/common/nm-secret-agent-simple.c index eeded86151..18be0c6735 100644 --- a/clients/common/nm-secret-agent-simple.c +++ b/clients/common/nm-secret-agent-simple.c @@ -799,7 +799,7 @@ try_spawn_vpn_auth_helper (RequestData *request, .auth_dialog_response = g_string_new_len (NULL, sizeof (data->read_buf)), .auth_dialog_pid = auth_dialog_pid, .request = request, - .secrets = secrets, + .secrets = g_ptr_array_ref (secrets), }; g_output_stream_write_async (auth_dialog_in, From 082ae508a0640ab7bf68f89fb6786653def6ef2c Mon Sep 17 00:00:00 2001 From: Beniamino Galvani Date: Mon, 4 Mar 2019 14:29:30 +0100 Subject: [PATCH 2/4] clients: fix keyfile string memory leak The return value of g_key_file_get_string() was leaked. Fixes: 5a0d67f739052512297af8e21273af4a7b355213 --- clients/common/nm-secret-agent-simple.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/clients/common/nm-secret-agent-simple.c b/clients/common/nm-secret-agent-simple.c index 18be0c6735..59e4c5a7b5 100644 --- a/clients/common/nm-secret-agent-simple.c +++ b/clients/common/nm-secret-agent-simple.c @@ -600,12 +600,15 @@ _auth_dialog_exited (GPid pid, int status, gpointer user_data) goto out; for (i = 1; groups[i]; i++) { + gs_free char *pretty_name = NULL; + if (!g_key_file_get_boolean (keyfile, groups[i], "IsSecret", NULL)) continue; if (!g_key_file_get_boolean (keyfile, groups[i], "ShouldAsk", NULL)) continue; - g_ptr_array_add (secrets, _secret_real_new_vpn_secret (g_key_file_get_string (keyfile, groups[i], "Label", NULL), + pretty_name = g_key_file_get_string (keyfile, groups[i], "Label", NULL); + g_ptr_array_add (secrets, _secret_real_new_vpn_secret (pretty_name, NM_SETTING (s_vpn), groups[i], nm_setting_vpn_get_service_type (s_vpn))); From 91a644d4a59db1c8a7c9e843b2a8d30aaf8f2d8c Mon Sep 17 00:00:00 2001 From: Beniamino Galvani Date: Mon, 4 Mar 2019 17:56:32 +0100 Subject: [PATCH 3/4] clients: fix i/o stream memory leaks Fixes: 5a0d67f739052512297af8e21273af4a7b355213 --- clients/common/nm-secret-agent-simple.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/clients/common/nm-secret-agent-simple.c b/clients/common/nm-secret-agent-simple.c index 59e4c5a7b5..a9a6bd2c96 100644 --- a/clients/common/nm-secret-agent-simple.c +++ b/clients/common/nm-secret-agent-simple.c @@ -537,6 +537,8 @@ typedef struct { GCancellable *cancellable; gulong cancellable_id; guint child_watch_id; + GInputStream *input_stream; + GOutputStream *output_stream; char read_buf[5]; } AuthDialogData; @@ -549,6 +551,8 @@ _auth_dialog_data_free (AuthDialogData *data) g_ptr_array_unref (data->secrets); g_spawn_close_pid (data->auth_dialog_pid); g_string_free (data->auth_dialog_response, TRUE); + g_object_unref (data->input_stream); + g_object_unref (data->output_stream); g_slice_free (AuthDialogData, data); } @@ -803,6 +807,8 @@ try_spawn_vpn_auth_helper (RequestData *request, .auth_dialog_pid = auth_dialog_pid, .request = request, .secrets = g_ptr_array_ref (secrets), + .input_stream = auth_dialog_out, + .output_stream = auth_dialog_in, }; g_output_stream_write_async (auth_dialog_in, From 22c87f0df8033e9a1995466e39b56935d696d38c Mon Sep 17 00:00:00 2001 From: Beniamino Galvani Date: Mon, 4 Mar 2019 17:56:44 +0100 Subject: [PATCH 4/4] clients: fix GVariantBuilder memory leak Fixes: acf86f68b33b14070d9b03a681fe94ffeead66ef --- clients/common/nm-secret-agent-simple.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/clients/common/nm-secret-agent-simple.c b/clients/common/nm-secret-agent-simple.c index a9a6bd2c96..cd3ce2eeea 100644 --- a/clients/common/nm-secret-agent-simple.c +++ b/clients/common/nm-secret-agent-simple.c @@ -1095,7 +1095,10 @@ nm_secret_agent_simple_response (NMSecretAgentSimple *self, gboolean has_vpn = FALSE; gboolean has_wg = FALSE; - settings = g_hash_table_new (nm_str_hash, g_str_equal); + settings = g_hash_table_new_full (nm_str_hash, + g_str_equal, + NULL, + (GDestroyNotify) g_variant_builder_unref); for (i = 0; i < secrets->len; i++) { SecretReal *secret = secrets->pdata[i];