Join GitHub today
GitHub is home to over 20 million developers working together to host and review code, manage projects, and build software together.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
Already on GitHub? Sign in to your account
[net] Avoid possibility of NULL pointer dereference in MarkBlockAsInFlight(...) #9549
Conversation
|
I think this can be a static_assert |
|
@theuni But |
|
Hmm, right. I suppose this would have to be a templated arg overloaded with nullptr_t to work, which would obviously be silly here. Nevermind! |
|
The right change here might be to just only write to the pointer if it is given as argument... (e.g., a nullcheck branch not an assert) Will, in normal execution, the assert ever panic? |
fanquake
added
the
P2P
label
Jan 14, 2017
|
From how I read it the assertion will never panic, but I agree this should be a nullcheck branch. I see the two calls to |
|
@JeremyRubin @robmcl4 Now changed from |
practicalswift
referenced this pull request
Jan 18, 2017
Open
6696b46: Clang Static Analyzer Report #9573
|
Any changes needed before merge? :-) |
| @@ -338,7 +338,9 @@ bool MarkBlockAsInFlight(NodeId nodeid, const uint256& hash, const Consensus::Pa | ||
| // Short-circuit most stuff in case its from the same node | ||
| map<uint256, pair<NodeId, list<QueuedBlock>::iterator> >::iterator itInFlight = mapBlocksInFlight.find(hash); | ||
| if (itInFlight != mapBlocksInFlight.end() && itInFlight->second.first == nodeid) { | ||
| - *pit = &itInFlight->second.second; | ||
| + if (pit != NULL) { |
paveljanik
Feb 28, 2017
Contributor
Why do you use different style then the style used just before return true?
practicalswift
Feb 28, 2017
Contributor
@paveljanik Are you referring to the braces? if (…) … vs. if (…) { … }?
|
@paveljanik Good point. Changed to |
practicalswift
referenced this pull request
May 10, 2017
Merged
Remove unused argument from MarkBlockAsInFlight(...) #10319
|
utACK 95543d8 Sorry for the delay. |
practicalswift
referenced this pull request
Jun 17, 2017
Open
[rpc]Avoid possibility of NULL pointer dereference in getblockchaininfo(...) #10619
|
utACK 95543d8 |
|
utACK 95543d8 |
practicalswift commentedJan 14, 2017
In the case that the branch ...
... is taken, there was prior to this commit an implicit assumption that
MarkBlockAsInFlight(...)was being called with its fifth and optional argument (pit) being present (and non-NULL).There are three calls to
MarkBlockAsReceived(...)and for two of these the optional fifth argument is not supplied, which means thatpitis being set to the default value ofNULL.This commit adds an assertion which makes the mentioned assumption explicit, and removes the possibility of a
NULLpointer dereference.