aboutsummaryrefslogtreecommitdiff
path: root/src/db.cpp
diff options
context:
space:
mode:
authorJeff Garzik <jgarzik@exmulti.com>2012-05-22 14:39:49 -0700
committerJeff Garzik <jgarzik@exmulti.com>2012-05-22 14:39:49 -0700
commit5d0f7c4f47e6b9aa382846dd9b4a034e724d461a (patch)
treece4b08cbe53dee3091698617fdcecb1665f7ccd0 /src/db.cpp
parentfa638ec8af92d6deaf17d3c09b03406808f19904 (diff)
parent8fe791e4e2db4b66f47d44d2ecaf734e2a36e5ed (diff)
downloadbitcoin-5d0f7c4f47e6b9aa382846dd9b4a034e724d461a.tar.xz
Merge pull request #1381 from jgarzik/check-deser
Prevent crashes due to missing or corrupted database records
Diffstat (limited to 'src/db.cpp')
-rw-r--r--src/db.cpp16
1 files changed, 14 insertions, 2 deletions
diff --git a/src/db.cpp b/src/db.cpp
index a0b9dc20f7..5c169fe0ca 100644
--- a/src/db.cpp
+++ b/src/db.cpp
@@ -416,9 +416,15 @@ bool CTxDB::ReadOwnerTxes(uint160 hash160, int nMinHeight, vector<CTransaction>&
string strType;
uint160 hashItem;
CDiskTxPos pos;
- ssKey >> strType >> hashItem >> pos;
int nItemHeight;
- ssValue >> nItemHeight;
+
+ try {
+ ssKey >> strType >> hashItem >> pos;
+ ssValue >> nItemHeight;
+ }
+ catch (std::exception &e) {
+ return error("%s() : deserialize error", __PRETTY_FUNCTION__);
+ }
// Read transaction
if (strType != "owner" || hashItem != hash160)
@@ -533,6 +539,8 @@ bool CTxDB::LoadBlockIndex()
return false;
// Unserialize
+
+ try {
string strType;
ssKey >> strType;
if (strType == "blockindex" && !fRequestShutdown)
@@ -564,6 +572,10 @@ bool CTxDB::LoadBlockIndex()
{
break; // if shutdown requested or finished loading block index
}
+ } // try
+ catch (std::exception &e) {
+ return error("%s() : deserialize error", __PRETTY_FUNCTION__);
+ }
}
pcursor->close();