aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKaz Wesley <kaz@lambdaverse.org>2018-11-14 11:53:27 -0800
committerfanquake <fanquake@gmail.com>2018-11-29 18:32:05 +0800
commit6f04264bbba18dd82157e2f5b8384e2f2b0969f2 (patch)
treeca25b888c9882c33fb5e88d6a1e45b788bc5760a
parent5782fdcd8c516fd8cc236beefbd9c91e03957f6a (diff)
downloadbitcoin-6f04264bbba18dd82157e2f5b8384e2f2b0969f2.tar.xz
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: b7b36decaf878a8c1dcfdb4a27196c730043474b
-rw-r--r--src/netaddress.cpp1
-rw-r--r--src/netaddress.h2
2 files changed, 1 insertions, 2 deletions
diff --git a/src/netaddress.cpp b/src/netaddress.cpp
index 778c2700f9..9c6daefef6 100644
--- a/src/netaddress.cpp
+++ b/src/netaddress.cpp
@@ -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)
diff --git a/src/netaddress.h b/src/netaddress.h
index cc0e4d4f12..dc55d8b1a8 100644
--- a/src/netaddress.h
+++ b/src/netaddress.h
@@ -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();