Skip to content

Commit bd60a9a

Browse files
committed
Merge bitcoin#19818: p2p: change CInv::type from int to uint32_t, fix UBSan warning
7984c39 test framework: serialize/deserialize inv type as unsigned int (Jon Atack) 407175e p2p: change CInv::type from int to uint32_t (Jon Atack) Pull request description: Fixes UBSan implicit-integer-sign-change issue per bitcoin#19610 (comment). Credit to Crypt-iQ for finding and reporting the issue and to vasild for the original review suggestion in bitcoin#19590 (review). Closes bitcoin#19678. ACKs for top commit: laanwj: ACK 7984c39 MarcoFalke: ACK 7984c39 🌻 vasild: ACK 7984c39 Tree-SHA512: 59f3a75f40ce066ca6f0bb1927197254238302b4073af1574bdbfe6ed580876437be804be4e47d51467d604f0d9e3a5875159f7f2edbb2351fdb2bb9465100b5
2 parents 69a13eb + 7984c39 commit bd60a9a

File tree

3 files changed

+7
-7
lines changed

3 files changed

+7
-7
lines changed

src/protocol.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ CInv::CInv()
163163
hash.SetNull();
164164
}
165165

166-
CInv::CInv(int typeIn, const uint256& hashIn) : type(typeIn), hash(hashIn) {}
166+
CInv::CInv(uint32_t typeIn, const uint256& hashIn) : type(typeIn), hash(hashIn) {}
167167

168168
bool operator<(const CInv& a, const CInv& b)
169169
{

src/protocol.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ class CInv
408408
{
409409
public:
410410
CInv();
411-
CInv(int typeIn, const uint256& hashIn);
411+
CInv(uint32_t typeIn, const uint256& hashIn);
412412

413413
SERIALIZE_METHODS(CInv, obj) { READWRITE(obj.type, obj.hash); }
414414

@@ -435,7 +435,7 @@ class CInv
435435
return type == MSG_BLOCK || type == MSG_FILTERED_BLOCK || type == MSG_CMPCT_BLOCK || type == MSG_WITNESS_BLOCK;
436436
}
437437

438-
int type;
438+
uint32_t type;
439439
uint256 hash;
440440
};
441441

test/functional/test_framework/messages.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -245,21 +245,21 @@ class CInv:
245245
MSG_TX | MSG_WITNESS_FLAG: "WitnessTx",
246246
MSG_BLOCK | MSG_WITNESS_FLAG: "WitnessBlock",
247247
MSG_FILTERED_BLOCK: "filtered Block",
248-
4: "CompactBlock",
249-
5: "WTX",
248+
MSG_CMPCT_BLOCK: "CompactBlock",
249+
MSG_WTX: "WTX",
250250
}
251251

252252
def __init__(self, t=0, h=0):
253253
self.type = t
254254
self.hash = h
255255

256256
def deserialize(self, f):
257-
self.type = struct.unpack("<i", f.read(4))[0]
257+
self.type = struct.unpack("<I", f.read(4))[0]
258258
self.hash = deser_uint256(f)
259259

260260
def serialize(self):
261261
r = b""
262-
r += struct.pack("<i", self.type)
262+
r += struct.pack("<I", self.type)
263263
r += ser_uint256(self.hash)
264264
return r
265265

0 commit comments

Comments
 (0)