From 5dc6af0a2183dbcf8676d6f670b53dc4dff79795 Mon Sep 17 00:00:00 2001 From: Julien Simonet Date: Mon, 7 Nov 2022 15:54:05 +0100 Subject: [PATCH] Ensure secret exists when tyring to read as text --- src/keytar_posix.cc | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/keytar_posix.cc b/src/keytar_posix.cc index 3a5ba7ca..e362aaf7 100644 --- a/src/keytar_posix.cc +++ b/src/keytar_posix.cc @@ -161,7 +161,16 @@ KEYTAR_OP_RESULT FindCredentials(const std::string& service, reinterpret_cast(g_hash_table_lookup(itemAttrs, "account"))); SecretValue* secret = secret_item_get_secret(item); - char* password = strdup(secret_value_get_text(secret)); + if (secret == NULL) { + // keystore is not open, secret is NULL which may lead to a crash in secret_value_get_text + continue; + } + + const gchar* secret_text = secret_value_get_text(secret); + char* password = NULL; + if (secret_text != NULL) { + password = strdup(secret_text); + } if (account == NULL || password == NULL) { if (account)