Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bunch of issues, reported by Coverity. #2202

Merged
merged 3 commits into from
Mar 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions src/lib/key-provider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/lib/rnp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<const rnp::KeyIDSearch *>(&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) {
Expand Down
2 changes: 1 addition & 1 deletion src/librekey/key_store_g10.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
5 changes: 2 additions & 3 deletions src/librekey/rnp_key_store.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
Loading