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: acf86f68b3
Signed-off-by: Thomas Haller <thaller@redhat.com>
This commit is contained in:
Thomas Haller 2014-09-22 09:03:21 +02:00
parent 3784678177
commit 85566e46d9
2 changed files with 3 additions and 3 deletions

View file

@ -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;
}

View file

@ -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);