Skip to content

Commit b7b36de

Browse files
committed
fix uninitialized read when stringifying an addrLocal
Reachable from either place where SetIP is used when our best-guess addrLocal for a peer is IPv4, but the peer tells us it's reaching us at an IPv6 address. In that case, SetIP turns an IPv4 address into an IPv6 address without setting the scopeId, which is subsequently read in GetSockAddr during CNetAddr::ToStringIP and passed to getnameinfo. Fix by ensuring every constructor initializes the scopeId field with something.
1 parent 8ebbef0 commit b7b36de

File tree

2 files changed

+1
-2
lines changed

2 files changed

+1
-2
lines changed

src/netaddress.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ static const unsigned char g_internal_prefix[] = { 0xFD, 0x6B, 0x88, 0xC0, 0x87,
1717
CNetAddr::CNetAddr()
1818
{
1919
memset(ip, 0, sizeof(ip));
20-
scopeId = 0;
2120
}
2221

2322
void CNetAddr::SetIP(const CNetAddr& ipIn)

src/netaddress.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class CNetAddr
3333
{
3434
protected:
3535
unsigned char ip[16]; // in network byte order
36-
uint32_t scopeId; // for scoped/link-local ipv6 addresses
36+
uint32_t scopeId{0}; // for scoped/link-local ipv6 addresses
3737

3838
public:
3939
CNetAddr();

0 commit comments

Comments
 (0)