From 407175e0c2bc797599ebd9c0a1f2ec89ad7af136 Mon Sep 17 00:00:00 2001 From: Jon Atack Date: Tue, 28 Jul 2020 10:47:07 +0200 Subject: p2p: change CInv::type from int to uint32_t fixes issue #19678 UBSan implicit-integer-sign-change Credit to Eugene (Crypt-iQ) for finding and reporting the issue and to Vasil Dimov (vasild) for the original suggestion --- src/protocol.cpp | 2 +- src/protocol.h | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/protocol.cpp b/src/protocol.cpp index c989aa3902..1f2e628545 100644 --- a/src/protocol.cpp +++ b/src/protocol.cpp @@ -163,7 +163,7 @@ CInv::CInv() hash.SetNull(); } -CInv::CInv(int typeIn, const uint256& hashIn) : type(typeIn), hash(hashIn) {} +CInv::CInv(uint32_t typeIn, const uint256& hashIn) : type(typeIn), hash(hashIn) {} bool operator<(const CInv& a, const CInv& b) { diff --git a/src/protocol.h b/src/protocol.h index 2e6c767cdd..415922dfb6 100644 --- a/src/protocol.h +++ b/src/protocol.h @@ -408,7 +408,7 @@ class CInv { public: CInv(); - CInv(int typeIn, const uint256& hashIn); + CInv(uint32_t typeIn, const uint256& hashIn); SERIALIZE_METHODS(CInv, obj) { READWRITE(obj.type, obj.hash); } @@ -425,7 +425,7 @@ public: // Combined-message helper methods bool IsGenTxMsg() const { return type == MSG_TX || type == MSG_WTX || type == MSG_WITNESS_TX; } - int type; + uint32_t type; uint256 hash; }; -- cgit v1.2.3 From 7984c39be11ca04460883365e1ae2a496aaa6c0e Mon Sep 17 00:00:00 2001 From: Jon Atack Date: Thu, 27 Aug 2020 15:10:15 +0200 Subject: test framework: serialize/deserialize inv type as unsigned int --- test/functional/test_framework/messages.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/functional/test_framework/messages.py b/test/functional/test_framework/messages.py index bd4a53876e..3b20c88fb0 100755 --- a/test/functional/test_framework/messages.py +++ b/test/functional/test_framework/messages.py @@ -244,8 +244,8 @@ class CInv: MSG_TX | MSG_WITNESS_FLAG: "WitnessTx", MSG_BLOCK | MSG_WITNESS_FLAG: "WitnessBlock", MSG_FILTERED_BLOCK: "filtered Block", - 4: "CompactBlock", - 5: "WTX", + MSG_CMPCT_BLOCK: "CompactBlock", + MSG_WTX: "WTX", } def __init__(self, t=0, h=0): @@ -253,12 +253,12 @@ class CInv: self.hash = h def deserialize(self, f): - self.type = struct.unpack("