From 85566e46d9f56d22c4ce9840877f913cec698c92 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Mon, 22 Sep 2014 09:03:21 +0200 Subject: [PATCH] libnm-core: fix crash in update-secrets when trying to clear all settings without providing a connection variant When the caller wants to clear all settings (thus providing @setting_name NULL), a NM_VARIANT_TYPE_CONNECTION variant is expected. This would lead to a crash when constructing the @error literal due to uninitialized @key. Clang also warns: Making all in . make[4]: Entering directory `./NetworkManager/libnm-core' CC nm-connection.lo ../libnm-core/nm-connection.c:1016:25: error: variable 'key' is uninitialized when used here [-Werror,-Wuninitialized] key); ^~~ ../libnm-core/nm-connection.c:962:17: note: initialize the variable 'key' to silence this warning const char *key; ^ = NULL 1 error generated. Fixes: acf86f68b33b14070d9b03a681fe94ffeead66ef Signed-off-by: Thomas Haller --- libnm-core/nm-connection.c | 4 ++-- libnm-core/tests/test-secrets.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/libnm-core/nm-connection.c b/libnm-core/nm-connection.c index 142fee4cd0..23e9f2159c 100644 --- a/libnm-core/nm-connection.c +++ b/libnm-core/nm-connection.c @@ -1012,8 +1012,8 @@ nm_connection_update_secrets (NMConnection *connection, if (!full_connection) { g_set_error_literal (error, NM_CONNECTION_ERROR, - NM_CONNECTION_ERROR_SETTING_NOT_FOUND, - key); + NM_CONNECTION_ERROR_INVALID_SETTING, + _("Update secrets expects a full connection, instead only a setting is provided.")); return FALSE; } diff --git a/libnm-core/tests/test-secrets.c b/libnm-core/tests/test-secrets.c index 738441ad47..d728223b39 100644 --- a/libnm-core/tests/test-secrets.c +++ b/libnm-core/tests/test-secrets.c @@ -716,7 +716,7 @@ test_update_secrets_null_setting_name_with_setting_hash (void) secrets = build_wep_secrets (wepkey); success = nm_connection_update_secrets (connection, NULL, secrets, &error); - g_assert_error (error, NM_CONNECTION_ERROR, NM_CONNECTION_ERROR_SETTING_NOT_FOUND); + g_assert_error (error, NM_CONNECTION_ERROR, NM_CONNECTION_ERROR_INVALID_SETTING); g_assert (!success); g_variant_unref (secrets);