]> Git Repo - VerusCoin.git/commitdiff
more addr message error checking
authors_nakamoto <s_nakamoto@1a98c847-1fd6-4fd8-948a-caf3550aa51b>
Tue, 15 Jun 2010 18:26:32 +0000 (18:26 +0000)
committers_nakamoto <s_nakamoto@1a98c847-1fd6-4fd8-948a-caf3550aa51b>
Tue, 15 Jun 2010 18:26:32 +0000 (18:26 +0000)
-- version 0.2.11

main.cpp
net.cpp
net.h
serialize.h

index aef68838cb55931de7492b52b1288434d8f6e8bd..13b7828dd593e3680d484e3772dba484994420b1 100644 (file)
--- a/main.cpp
+++ b/main.cpp
@@ -1926,7 +1926,9 @@ bool ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv)
     {\r
         vector<CAddress> vAddr;\r
         vRecv >> vAddr;\r
-        if (vAddr.size() > 50000) // lower this to 1000 later\r
+        if (pfrom->nVersion < 200) // don't want addresses from 0.1.5\r
+            return true;\r
+        if (vAddr.size() > 1000)\r
             return error("message addr size() = %d", vAddr.size());\r
 \r
         // Store the new addresses\r
@@ -2311,6 +2313,7 @@ bool SendMessages(CNode* pto, bool fSendTrickle)
                 if (pto->setAddrKnown.insert(addr).second)\r
                 {\r
                     vAddr.push_back(addr);\r
+                    // receiver rejects addr messages larger than 1000\r
                     if (vAddr.size() >= 1000)\r
                     {\r
                         pto->PushMessage("addr", vAddr);\r
diff --git a/net.cpp b/net.cpp
index c5659dc9231f2ac0c5f5b1ae59a0f6fad4877836..59d40dc121d0d5c77b1990db04f5a401451c40b2 100644 (file)
--- a/net.cpp
+++ b/net.cpp
@@ -968,9 +968,9 @@ bool OpenNetworkConnection(const CAddress& addrConnect)
     if (addrLocalHost.IsRoutable() && !fUseProxy)\r
     {\r
         // Advertise our address\r
-        vector<CAddress> vAddrToSend;\r
-        vAddrToSend.push_back(addrLocalHost);\r
-        pnode->PushMessage("addr", vAddrToSend);\r
+        vector<CAddress> vAddr;\r
+        vAddr.push_back(addrLocalHost);\r
+        pnode->PushMessage("addr", vAddr);\r
     }\r
 \r
     // Get as many addresses as we can\r
diff --git a/net.h b/net.h
index 9ce848f636dee29c43ce450069b9ee47431426f3..11197cc4290322bdcc3c6a10b40f66b5b6bcfc83 100644 (file)
--- a/net.h
+++ b/net.h
@@ -289,16 +289,24 @@ public:
 \r
     bool IsRoutable() const\r
     {\r
-        return !(GetByte(3) == 10 ||\r
-                 (GetByte(3) == 192 && GetByte(2) == 168) ||\r
-                 GetByte(3) == 127 ||\r
-                 GetByte(3) == 0 ||\r
-                 ip == 0 ||\r
-                 ip == INADDR_NONE);\r
+        return IsValid() &&\r
+            !(GetByte(3) == 10 ||\r
+              (GetByte(3) == 192 && GetByte(2) == 168) ||\r
+              GetByte(3) == 127 ||\r
+              GetByte(3) == 0);\r
     }\r
 \r
     bool IsValid() const\r
     {\r
+        // Clean up 3-byte shifted addresses caused by garbage in size field\r
+        // of addr messages from versions before 0.2.9 checksum.\r
+        // Two consecutive addr messages look like this:\r
+        // header20 vectorlen3 addr26 addr26 addr26 header20 vectorlen3 addr26 addr26 addr26...\r
+        // so if the first length field is garbled, it reads the second batch\r
+        // of addr misaligned by 3 bytes.\r
+        if (memcmp(pchReserved, pchIPv4+3, sizeof(pchIPv4)-3) == 0)\r
+            return false;\r
+\r
         return (ip != 0 && ip != INADDR_NONE && port != htons(USHRT_MAX));\r
     }\r
 \r
@@ -619,7 +627,7 @@ public:
         // Known checking here is only to save space from duplicates.\r
         // SendMessages will filter it again for knowns that were added\r
         // after addresses were pushed.\r
-        if (!setAddrKnown.count(addr))\r
+        if (addr.IsValid() && !setAddrKnown.count(addr))\r
             vAddrToSend.push_back(addr);\r
     }\r
 \r
index 25dcfb474637cec3f42e059ea1dc16df5268a939..f2d368986a868aed7fae326a6e5424a18b291de6 100644 (file)
@@ -19,7 +19,7 @@ class CScript;
 class CDataStream;\r
 class CAutoFile;\r
 \r
-static const int VERSION = 210;\r
+static const int VERSION = 211;\r
 static const char* pszSubVer = ".0";\r
 \r
 \r
This page took 0.039732 seconds and 4 git commands to generate.