From dcbfe13f64bb1f511a0c65e34153e02f329b6dec Mon Sep 17 00:00:00 2001 From: Nickolay Olshevsky Date: Sun, 28 Jul 2024 11:26:55 +0300 Subject: [PATCH] Fix CID 1547469: Integer handling issues --- src/lib/fingerprint.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/lib/fingerprint.cpp b/src/lib/fingerprint.cpp index bc5c9cfec..b503a1356 100644 --- a/src/lib/fingerprint.cpp +++ b/src/lib/fingerprint.cpp @@ -30,6 +30,7 @@ */ #include +#include #include "fingerprint.h" #include "crypto/hash.hpp" #include @@ -106,8 +107,13 @@ pgp_keyid(pgp_key_id_t &keyid, const pgp_key_pkt_t &key) if (ret) { return ret; } - size_t inc = key.version == PGP_V4 ? fp.length - keyid.size() : 0; - (void) memcpy(keyid.data(), fp.fingerprint + inc, keyid.size()); + if (key.version == PGP_V4) { + assert(fp.length == PGP_FINGERPRINT_V4_SIZE); + const size_t inc = PGP_FINGERPRINT_V4_SIZE - PGP_KEY_ID_SIZE; + memcpy(keyid.data(), fp.fingerprint + inc, keyid.size()); + } else { + memcpy(keyid.data(), fp.fingerprint, keyid.size()); + } return RNP_SUCCESS; } default: