Skip to content

Commit 29c9bdc

Browse files
Handle unsuccessful fseek(...):s
1 parent 57c57df commit 29c9bdc

File tree

3 files changed

+10
-3
lines changed

3 files changed

+10
-3
lines changed

src/index/txindex.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,9 @@ bool TxIndex::FindTx(const uint256& tx_hash, uint256& block_hash, CTransactionRe
268268
CBlockHeader header;
269269
try {
270270
file >> header;
271-
fseek(file.Get(), postx.nTxOffset, SEEK_CUR);
271+
if (fseek(file.Get(), postx.nTxOffset, SEEK_CUR)) {
272+
return error("%s: fseek(...) failed", __func__);
273+
}
272274
file >> tx;
273275
} catch (const std::exception& e) {
274276
return error("%s: Deserialize or I/O error - %s", __func__, e.what());

src/logging.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,10 @@ void BCLog::Logger::ShrinkDebugFile()
254254
{
255255
// Restart the file with some of the end
256256
std::vector<char> vch(RECENT_DEBUG_HISTORY_SIZE, 0);
257-
fseek(file, -((long)vch.size()), SEEK_END);
257+
if (fseek(file, -((long)vch.size()), SEEK_END)) {
258+
fclose(file);
259+
return;
260+
}
258261
int nBytes = fread(vch.data(), 1, vch.size(), file);
259262
fclose(file);
260263

src/util.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -887,7 +887,9 @@ void AllocateFileRange(FILE *file, unsigned int offset, unsigned int length) {
887887
// Fallback version
888888
// TODO: just write one byte per block
889889
static const char buf[65536] = {};
890-
fseek(file, offset, SEEK_SET);
890+
if (fseek(file, offset, SEEK_SET)) {
891+
return;
892+
}
891893
while (length > 0) {
892894
unsigned int now = 65536;
893895
if (length < now)

0 commit comments

Comments
 (0)