aboutsummaryrefslogtreecommitdiff
path: root/net.h
diff options
context:
space:
mode:
authors_nakamoto <s_nakamoto@1a98c847-1fd6-4fd8-948a-caf3550aa51b>2010-06-15 18:26:32 +0000
committers_nakamoto <s_nakamoto@1a98c847-1fd6-4fd8-948a-caf3550aa51b>2010-06-15 18:26:32 +0000
commite5681bb12154bae75977d091190e924d8e6984cd (patch)
tree6bd0c2671065191db077713ab84b8e7832954ba5 /net.h
parentbed005b639a0db8c8d98022609fe03e0ec55e18a (diff)
downloadbitcoin-e5681bb12154bae75977d091190e924d8e6984cd.tar.xz
more addr message error checkingv0.2.11
-- version 0.2.11 git-svn-id: https://bitcoin.svn.sourceforge.net/svnroot/bitcoin/trunk@83 1a98c847-1fd6-4fd8-948a-caf3550aa51b
Diffstat (limited to 'net.h')
-rw-r--r--net.h22
1 files changed, 15 insertions, 7 deletions
diff --git a/net.h b/net.h
index 9ce848f636..11197cc429 100644
--- a/net.h
+++ b/net.h
@@ -289,16 +289,24 @@ public:
bool IsRoutable() const
{
- return !(GetByte(3) == 10 ||
- (GetByte(3) == 192 && GetByte(2) == 168) ||
- GetByte(3) == 127 ||
- GetByte(3) == 0 ||
- ip == 0 ||
- ip == INADDR_NONE);
+ return IsValid() &&
+ !(GetByte(3) == 10 ||
+ (GetByte(3) == 192 && GetByte(2) == 168) ||
+ GetByte(3) == 127 ||
+ GetByte(3) == 0);
}
bool IsValid() const
{
+ // Clean up 3-byte shifted addresses caused by garbage in size field
+ // of addr messages from versions before 0.2.9 checksum.
+ // Two consecutive addr messages look like this:
+ // header20 vectorlen3 addr26 addr26 addr26 header20 vectorlen3 addr26 addr26 addr26...
+ // so if the first length field is garbled, it reads the second batch
+ // of addr misaligned by 3 bytes.
+ if (memcmp(pchReserved, pchIPv4+3, sizeof(pchIPv4)-3) == 0)
+ return false;
+
return (ip != 0 && ip != INADDR_NONE && port != htons(USHRT_MAX));
}
@@ -619,7 +627,7 @@ public:
// Known checking here is only to save space from duplicates.
// SendMessages will filter it again for knowns that were added
// after addresses were pushed.
- if (!setAddrKnown.count(addr))
+ if (addr.IsValid() && !setAddrKnown.count(addr))
vAddrToSend.push_back(addr);
}