Skip to content
This repository was archived by the owner on Dec 15, 2022. It is now read-only.

Commit 5dc6af0

Browse files
committed
Ensure secret exists when tyring to read as text
1 parent deae59a commit 5dc6af0

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/keytar_posix.cc

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,16 @@ KEYTAR_OP_RESULT FindCredentials(const std::string& service,
161161
reinterpret_cast<char*>(g_hash_table_lookup(itemAttrs, "account")));
162162

163163
SecretValue* secret = secret_item_get_secret(item);
164-
char* password = strdup(secret_value_get_text(secret));
164+
if (secret == NULL) {
165+
// keystore is not open, secret is NULL which may lead to a crash in secret_value_get_text
166+
continue;
167+
}
168+
169+
const gchar* secret_text = secret_value_get_text(secret);
170+
char* password = NULL;
171+
if (secret_text != NULL) {
172+
password = strdup(secret_text);
173+
}
165174

166175
if (account == NULL || password == NULL) {
167176
if (account)

0 commit comments

Comments
 (0)