HomePhabricator

Merge #11655: net: Assert state.m_chain_sync.m_work_header in ConsiderEviction

Description

Merge #11655: net: Assert state.m_chain_sync.m_work_header in ConsiderEviction

Summary:
63c2d83 Explicitly state assumption that state.m_chain_sync.m_work_header != nullptr in ConsiderEviction (practicalswift)

Pull request description:

Explicitly state assumption that `state.m_chain_sync.m_work_header != nullptr` in `ConsiderEviction(…)`.

Static analyzer (and humans!) will see the null-check in ...

```
else if (state.m_chain_sync.m_timeout == 0 || (state.m_chain_sync.m_work_header != nullptr && ...
```

... and infer that `state.m_chain_sync.m_work_header` might be set to `nullptr` when reaching `else if (state.m_chain_sync.m_timeout > 0 && time_in_seconds > state.m_chain_sync.m_timeout)` and thus flag `state.m_chain_sync.m_work_header->GetBlockHash().ToString()` as a potential null pointer dereference.

This commit makes the tacit assumption of `state.m_chain_sync.m_work_header != nullptr` explicit.

Code introduced in 5a6d00c6defc587e22c93e63029fdd538ce8858d ("Permit disconnection of outbound peers on bad/slow chains") which was merged into master four days ago.

Friendly ping @sdaftuar :-)

Tree-SHA512: 32e5631025b7ba7556a02c89d040fbe339c482a03f28d0dbc9871c699e1f8ac867619b89c5fd41fdcfcf0dc4d7c859295b26ccd988572145cc244261aec18ce9

Backport of Core PR11655
https://github.com/bitcoin/bitcoin/pull/11655

Test Plan:

make check
test_runner.py

Reviewers: jasonbcox, deadalnix, Fabien, O1 Bitcoin ABC, #bitcoin_abc

Reviewed By: jasonbcox, O1 Bitcoin ABC, #bitcoin_abc

Differential Revision: https://reviews.bitcoinabc.org/D3199

Details

Provenance
Wladimir J. van der Laan <laanwj@gmail.com>Authored on Nov 15 2017, 12:55
nakihitoCommitted on Jun 4 2019, 22:37
nakihitoPushed on Jun 4 2019, 23:01
Reviewer
Restricted Owners Package
Differential Revision
D3199: Merge #11655: net: Assert state.m_chain_sync.m_work_header in ConsiderEviction
Parents
rSTAGING3a8bd492d2ee: Remove implicit parameter from GetSerializeSize
Branches
Unknown
Tags
Unknown
References
tag: phabricator/base/9136