[util] Avoid integer overflow in CheckDiskSpace

This commit is contained in:
dergoegge 2023-03-09 18:17:06 +01:00
parent 40c6c85c05
commit 4517419628

View file

@ -1631,10 +1631,11 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
// On first startup, warn on low block storage space
if (!fReindex && !fReindexChainState && chain_active_height <= 1) {
uint64_t assumed_chain_bytes{chainparams.AssumedBlockchainSize() * 1024 * 1024 * 1024};
uint64_t additional_bytes_needed{
chainman.m_blockman.IsPruneMode() ?
chainman.m_blockman.GetPruneTarget() :
chainparams.AssumedBlockchainSize() * 1024 * 1024 * 1024};
std::min(chainman.m_blockman.GetPruneTarget(), assumed_chain_bytes) :
assumed_chain_bytes};
if (!CheckDiskSpace(args.GetBlocksDirPath(), additional_bytes_needed)) {
InitWarning(strprintf(_(