From b561dcebc0c59833f345cca7374886c6418abc35 Mon Sep 17 00:00:00 2001 From: Nickolay Olshevsky Date: Mon, 18 Mar 2024 18:23:20 +0200 Subject: [PATCH 1/3] Fix CID 1534296: unchecked return. --- src/librekey/rnp_key_store.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/librekey/rnp_key_store.cpp b/src/librekey/rnp_key_store.cpp index 8a09357280..15a382bd8b 100644 --- a/src/librekey/rnp_key_store.cpp +++ b/src/librekey/rnp_key_store.cpp @@ -145,9 +145,8 @@ KeyStore::write() } for (auto &key : keys) { - char grip[PGP_FINGERPRINT_HEX_SIZE] = {0}; - rnp::hex_encode(key.grip().data(), key.grip().size(), grip, sizeof(grip)); - snprintf(chpath, sizeof(chpath), "%s/%s.key", path.c_str(), grip); + auto grip = rnp::bin_to_hex(key.grip().data(), key.grip().size()); + snprintf(chpath, sizeof(chpath), "%s/%s.key", path.c_str(), grip.c_str()); if (init_tmpfile_dest(&keydst, chpath, true)) { RNP_LOG("failed to create file"); From 8b7d36e71d6136a1cbd3a6454628dc0738932549 Mon Sep 17 00:00:00 2001 From: Nickolay Olshevsky Date: Mon, 18 Mar 2024 18:28:41 +0200 Subject: [PATCH 2/3] Fix CID 1540730, 1540707, 1540701: Uninitialized variables (UNINIT) --- src/lib/key-provider.cpp | 10 ++++++---- src/librekey/key_store_g10.cpp | 2 +- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/lib/key-provider.cpp b/src/lib/key-provider.cpp index 60277cb56d..b6e27a7141 100644 --- a/src/lib/key-provider.cpp +++ b/src/lib/key-provider.cpp @@ -97,22 +97,24 @@ KeySearch::create(const std::string &name, const std::string &value) return nullptr; } return create(pgp_fingerprint_t(binval)); - case Type::KeyID: + case Type::KeyID: { if (binval.size() != PGP_KEY_ID_SIZE) { RNP_LOG("Invalid keyid: %s", value.c_str()); return nullptr; } - pgp_key_id_t keyid; + pgp_key_id_t keyid{}; memcpy(keyid.data(), binval.data(), keyid.size()); return create(keyid); - case Type::Grip: + } + case Type::Grip: { if (binval.size() != PGP_KEY_GRIP_SIZE) { RNP_LOG("Invalid grip: %s", value.c_str()); return nullptr; } - pgp_key_grip_t grip; + pgp_key_grip_t grip{}; memcpy(grip.data(), binval.data(), grip.size()); return create(grip); + } default: return nullptr; } diff --git a/src/librekey/key_store_g10.cpp b/src/librekey/key_store_g10.cpp index 96a882344c..fa3da34584 100644 --- a/src/librekey/key_store_g10.cpp +++ b/src/librekey/key_store_g10.cpp @@ -908,7 +908,7 @@ KeyStore::load_g10(pgp_source_t &src, const KeyProvider *key_provider) /* copy public key fields if any */ pgp_key_t key; if (key_provider) { - pgp_key_grip_t grip; + pgp_key_grip_t grip{}; if (!seckey.material.get_grip(grip)) { return false; } From 69b25d11be6373d60e3e2aecd4bc9fb90aac7581 Mon Sep 17 00:00:00 2001 From: Nickolay Olshevsky Date: Mon, 18 Mar 2024 18:32:42 +0200 Subject: [PATCH 3/3] Fix CID 1540660. --- src/lib/rnp.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/rnp.cpp b/src/lib/rnp.cpp index 7e1a1965d6..24e7450fa6 100644 --- a/src/lib/rnp.cpp +++ b/src/lib/rnp.cpp @@ -3275,7 +3275,7 @@ ffi_decrypt_key_provider(const pgp_key_request_ctx_t *ctx, void *userdata) if (ctx->secret && (ctx->search.type() == rnp::KeySearch::Type::KeyID)) { auto ksearch = dynamic_cast(&ctx->search); assert(ksearch != nullptr); - hidden = ksearch->hidden(); + hidden = ksearch && ksearch->hidden(); } /* default to the FFI key provider if not hidden keyid request */ if (!hidden) {