Skip to content

Commit

Permalink
Fix segfault in accrual age calculation
Browse files Browse the repository at this point in the history
This fixes a segmentation fault caused by dereferencing a null pointer
when attempting to calculate accrual age for a CPID with no beacon.
  • Loading branch information
cyrossignol committed Jun 17, 2020
1 parent 5d360bb commit 4fb9d42
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/neuralnet/accrual/snapshot.h
Original file line number Diff line number Diff line change
Expand Up @@ -234,13 +234,15 @@ class SnapshotAccrualComputer : public IAccrualComputer, SnapshotCalculator
// a superblock after contract improvements for more accurate age.
//
if (m_account.IsNew()) {
const int64_t beacon_time = GetBeaconRegistry().Try(m_cpid)->m_timestamp;
if (const BeaconOption beacon = GetBeaconRegistry().Try(m_cpid)) {
const int64_t beacon_time = beacon->m_timestamp;

if (beacon_time <= 0) {
return 0;
if (beacon_time > 0) {
return m_payment_time - beacon_time;
}
}

return m_payment_time - beacon_time;
return 0;
}

return SnapshotCalculator::AccrualAge(m_account);
Expand Down

0 comments on commit 4fb9d42

Please sign in to comment.