aboutsummaryrefslogtreecommitdiff
path: root/src/db.cpp
diff options
context:
space:
mode:
authorJeff Garzik <[email protected]>2012-10-08 13:41:57 -0400
committerLuke Dashjr <[email protected]>2012-10-20 23:31:30 +0000
commit12f341d2530bfda86ce11d61c3fb9bb673904bef (patch)
treea0a3a932ab11b2afc49fc90007c5e6d37efd0c97 /src/db.cpp
parentFix a use-after-free problem in initialization (#1920) (diff)
downloaddiscoin-12f341d2530bfda86ce11d61c3fb9bb673904bef.tar.xz
discoin-12f341d2530bfda86ce11d61c3fb9bb673904bef.zip
CAddrMan: verify pchMessageStart file marker, before reading address data
This avoids the case where you read the address data, before noticing it is the wrong network.
Diffstat (limited to 'src/db.cpp')
-rw-r--r--src/db.cpp12
1 files changed, 7 insertions, 5 deletions
diff --git a/src/db.cpp b/src/db.cpp
index 9ad67892f..297240c84 100644
--- a/src/db.cpp
+++ b/src/db.cpp
@@ -909,20 +909,22 @@ bool CAddrDB::Read(CAddrMan& addr)
if (hashIn != hashTmp)
return error("CAddrman::Read() : checksum mismatch; data corrupted");
- // de-serialize address data
unsigned char pchMsgTmp[4];
try {
+ // de-serialize file header (pchMessageStart magic number) and
ssPeers >> FLATDATA(pchMsgTmp);
+
+ // verify the network matches ours
+ if (memcmp(pchMsgTmp, pchMessageStart, sizeof(pchMsgTmp)))
+ return error("CAddrman::Read() : invalid network magic number");
+
+ // de-serialize address data into one CAddrMan object
ssPeers >> addr;
}
catch (std::exception &e) {
return error("CAddrman::Read() : I/O error or stream data corrupted");
}
- // finally, verify the network matches ours
- if (memcmp(pchMsgTmp, pchMessageStart, sizeof(pchMsgTmp)))
- return error("CAddrman::Read() : invalid network magic number");
-
return true;
}