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.

Github-Pull: #14728
Rebased-From: b7b36decaf
This commit is contained in:
Kaz Wesley 2018-11-14 11:53:27 -08:00 committed by fanquake
parent 5782fdcd8c
commit 6f04264bbb
No known key found for this signature in database
GPG key ID: 2EEB9F5CC09526C1
2 changed files with 1 additions and 2 deletions

View file

@ -17,7 +17,6 @@ static const unsigned char g_internal_prefix[] = { 0xFD, 0x6B, 0x88, 0xC0, 0x87,
CNetAddr::CNetAddr()
{
memset(ip, 0, sizeof(ip));
scopeId = 0;
}
void CNetAddr::SetIP(const CNetAddr& ipIn)

View file

@ -33,7 +33,7 @@ class CNetAddr
{
protected:
unsigned char ip[16]; // in network byte order
uint32_t scopeId; // for scoped/link-local ipv6 addresses
uint32_t scopeId{0}; // for scoped/link-local ipv6 addresses
public:
CNetAddr();