aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorpracticalswift <practicalswift@users.noreply.github.com>2018-05-02 12:12:55 +0200
committerpracticalswift <practicalswift@users.noreply.github.com>2018-05-02 12:12:55 +0200
commit29c9bdcc141afb14fc9e1213f49de4fcded6ce0c (patch)
treecc332a0390a37bbbc01fbaf098bde75eab166de6 /src
parent57c57df86f14874cfc4b280e04a7f44b19839c26 (diff)
downloadbitcoin-29c9bdcc141afb14fc9e1213f49de4fcded6ce0c.tar.xz
Handle unsuccessful fseek(...):s
Diffstat (limited to 'src')
-rw-r--r--src/index/txindex.cpp4
-rw-r--r--src/logging.cpp5
-rw-r--r--src/util.cpp4
3 files changed, 10 insertions, 3 deletions
diff --git a/src/index/txindex.cpp b/src/index/txindex.cpp
index 2a661f0330..ad1682c9cf 100644
--- a/src/index/txindex.cpp
+++ b/src/index/txindex.cpp
@@ -268,7 +268,9 @@ bool TxIndex::FindTx(const uint256& tx_hash, uint256& block_hash, CTransactionRe
CBlockHeader header;
try {
file >> header;
- fseek(file.Get(), postx.nTxOffset, SEEK_CUR);
+ if (fseek(file.Get(), postx.nTxOffset, SEEK_CUR)) {
+ return error("%s: fseek(...) failed", __func__);
+ }
file >> tx;
} catch (const std::exception& e) {
return error("%s: Deserialize or I/O error - %s", __func__, e.what());
diff --git a/src/logging.cpp b/src/logging.cpp
index 10a3b18958..2a55d3665b 100644
--- a/src/logging.cpp
+++ b/src/logging.cpp
@@ -254,7 +254,10 @@ void BCLog::Logger::ShrinkDebugFile()
{
// Restart the file with some of the end
std::vector<char> vch(RECENT_DEBUG_HISTORY_SIZE, 0);
- fseek(file, -((long)vch.size()), SEEK_END);
+ if (fseek(file, -((long)vch.size()), SEEK_END)) {
+ fclose(file);
+ return;
+ }
int nBytes = fread(vch.data(), 1, vch.size(), file);
fclose(file);
diff --git a/src/util.cpp b/src/util.cpp
index 9a3067259f..b4d0a61ab2 100644
--- a/src/util.cpp
+++ b/src/util.cpp
@@ -887,7 +887,9 @@ void AllocateFileRange(FILE *file, unsigned int offset, unsigned int length) {
// Fallback version
// TODO: just write one byte per block
static const char buf[65536] = {};
- fseek(file, offset, SEEK_SET);
+ if (fseek(file, offset, SEEK_SET)) {
+ return;
+ }
while (length > 0) {
unsigned int now = 65536;
if (length < now)