aboutsummaryrefslogtreecommitdiff
path: root/src/db.cpp
diff options
context:
space:
mode:
authorGregory Maxwell <greg@xiph.org>2012-10-20 15:06:25 -0700
committerGregory Maxwell <greg@xiph.org>2012-10-20 15:06:25 -0700
commit67e2c8a40a4ced7face7be64bf71c6e8086b4bcc (patch)
tree48aebae6028591fb375850c765ee478ab8ec1f32 /src/db.cpp
parentf50fb5470b1d3a65a513b3a9a77209ccad590a19 (diff)
parentbd2e1405711f6ba81adadb6ea6206e916c29453b (diff)
Merge pull request #1916 from jgarzik/caddrdb-bug
Fix: CAddrMan: verify pchMessageStart file marker, before reading address data
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 8738a0af8e..cf96fe6e38 100644
--- a/src/db.cpp
+++ b/src/db.cpp
@@ -567,20 +567,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;
}