diff options
author | Gregory Maxwell <greg@xiph.org> | 2012-10-20 15:06:25 -0700 |
---|---|---|
committer | Gregory Maxwell <greg@xiph.org> | 2012-10-20 15:06:25 -0700 |
commit | 67e2c8a40a4ced7face7be64bf71c6e8086b4bcc (patch) | |
tree | 48aebae6028591fb375850c765ee478ab8ec1f32 | |
parent | f50fb5470b1d3a65a513b3a9a77209ccad590a19 (diff) | |
parent | bd2e1405711f6ba81adadb6ea6206e916c29453b (diff) |
Merge pull request #1916 from jgarzik/caddrdb-bug
Fix: CAddrMan: verify pchMessageStart file marker, before reading address data
-rw-r--r-- | src/db.cpp | 12 |
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; } |