aboutsummaryrefslogtreecommitdiff
path: root/src/db.cpp
diff options
context:
space:
mode:
authorJeff Garzik <jgarzik@exmulti.com>2012-05-22 15:12:52 -0400
committerLuke Dashjr <luke-jr+git@utopios.org>2012-05-22 22:47:51 +0000
commitb6862f7b74d0ea7442cf3b9eec7b9556ca47ce4b (patch)
treebcad1d45f93faab126a26e237d98bf65a0fe532b /src/db.cpp
parent8a39b0d613e6d79b7118eb929b5fe68220584f07 (diff)
downloadbitcoin-b6862f7b74d0ea7442cf3b9eec7b9556ca47ce4b.tar.xz
Prevent crashes due to missing or corrupted database records
Any problems seen during deserialization will throw an uncaught exception, crashing the entire bitcoin process. Properly return an error instead, so that we may at least log the error and gracefully shutdown other portions of the app.
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 68d317106d..d509253e4e 100644
--- a/src/db.cpp
+++ b/src/db.cpp
@@ -390,9 +390,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)
@@ -512,6 +518,8 @@ bool CTxDB::LoadBlockIndex()
return false;
// Unserialize
+
+ try {
string strType;
ssKey >> strType;
if (strType == "blockindex")
@@ -543,6 +551,10 @@ bool CTxDB::LoadBlockIndex()
{
break;
}
+ } // try
+ catch (std::exception &e) {
+ return error("%s() : deserialize error", __PRETTY_FUNCTION__);
+ }
}
pcursor->close();