From 9077b2dc5875696c870440fb788ce5ce3e19787e Mon Sep 17 00:00:00 2001 From: Nickolay Olshevsky Date: Wed, 23 Oct 2024 13:49:30 +0300 Subject: [PATCH] Fix bunch of minor coverity issues. --- src/lib/pgp-key.cpp | 2 +- src/lib/sig_subpacket.cpp | 4 ++-- src/lib/sig_subpacket.hpp | 5 +++-- src/librepgp/stream-sig.cpp | 3 +++ src/librepgp/stream-sig.h | 4 ++-- 5 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/lib/pgp-key.cpp b/src/lib/pgp-key.cpp index 601c72a9..918d799a 100644 --- a/src/lib/pgp-key.cpp +++ b/src/lib/pgp-key.cpp @@ -2151,7 +2151,7 @@ pgp_key_t::validate_sig(pgp_signature_info_t & sinfo, if (!subpkt->critical() || (subpkt->type() != pgp::pkt::sigsub::Type::NotationData)) { continue; } - auto notation = dynamic_cast(*subpkt); + auto ¬ation = dynamic_cast(*subpkt); RNP_LOG("unknown critical notation: %s", notation.name().c_str()); sinfo.valid = false; } diff --git a/src/lib/sig_subpacket.cpp b/src/lib/sig_subpacket.cpp index ebbffcaa..b13ab6b7 100644 --- a/src/lib/sig_subpacket.cpp +++ b/src/lib/sig_subpacket.cpp @@ -672,11 +672,11 @@ bool EmbeddedSignature::parse_data(const uint8_t *data, size_t size) { pgp_packet_body_t pkt(data, size); - pgp_signature_t sig{}; + pgp_signature_t sig; if (sig.parse(pkt)) { return false; } - signature_ = std::unique_ptr(new pgp_signature_t(sig)); + signature_ = std::unique_ptr(new pgp_signature_t(std::move(sig))); return true; } diff --git a/src/lib/sig_subpacket.hpp b/src/lib/sig_subpacket.hpp index 7a8aa413..82732545 100644 --- a/src/lib/sig_subpacket.hpp +++ b/src/lib/sig_subpacket.hpp @@ -471,7 +471,8 @@ class RevocationKey : public Raw { public: RevocationKey(bool hashed = true, bool critical = false) - : Raw(Type::RevocationKey, hashed, critical){}; + : Raw(Type::RevocationKey, hashed, critical), rev_class_(0), + alg_(PGP_PKA_NOTHING), fp_{} {}; uint8_t rev_class() const noexcept @@ -866,7 +867,7 @@ class IssuerFingerprint : public Raw { public: IssuerFingerprint(bool hashed = true, bool critical = false) - : Raw(Type::IssuerFingerprint, hashed, critical), version_(0) + : Raw(Type::IssuerFingerprint, hashed, critical), version_(0), fp_{} { } diff --git a/src/librepgp/stream-sig.cpp b/src/librepgp/stream-sig.cpp index bbdcbee1..0715ee25 100644 --- a/src/librepgp/stream-sig.cpp +++ b/src/librepgp/stream-sig.cpp @@ -436,6 +436,9 @@ pgp_signature_t::set_preferred(const std::vector &data, sigsub::Type ty auto sub = sigsub::Raw::create(type); auto pref = dynamic_cast(sub.get()); + if (!pref) { + return; + } pref->set_algs(data); add_subpkt(std::move(sub)); } diff --git a/src/librepgp/stream-sig.h b/src/librepgp/stream-sig.h index 89037442..1cecaa77 100644 --- a/src/librepgp/stream-sig.h +++ b/src/librepgp/stream-sig.h @@ -53,13 +53,13 @@ typedef struct pgp_signature_t { /* common v3 and v4 fields */ pgp_pubkey_alg_t palg; pgp_hash_alg_t halg; - std::array lbits; + std::array lbits{}; std::vector hashed_data; std::vector material_buf; /* raw signature material */ /* v3 - only fields */ uint32_t creation_time; - pgp_key_id_t signer; + pgp_key_id_t signer{}; /* common v4, v5 and v6 fields */ pgp::pkt::sigsub::List subpkts;