In ContextualCheckBlock, we are checking if pindexPrev == nullptr conditionally at the start, but then assume it is non-null later. This removes the latter assumption.
validation: assert that pindexPrev is non-null when required #14834
pull kallewoof wants to merge 1 commits into bitcoin:master from kallewoof:20181129-contextualcheckblock-pindexprev-nullness changing 1 files +1 −0-
kallewoof commented at 4:19 AM on November 29, 2018: member
-
luke-jr commented at 4:22 AM on November 29, 2018: member
Is it even hypothetically possible for LOCKTIME_MEDIAN_TIME_PAST to be set on a genesis block?
Precedence is non-obvious in this case, so prefer adding parenthesis for clarity at least.
- fanquake added the label Validation on Nov 29, 2018
-
kallewoof commented at 4:29 AM on November 29, 2018: member
That's a good point. Is that the only case
ContextualCheckBlockis called withpindexPrev == nullptr? (When block is the genesis block) -
luke-jr commented at 4:32 AM on November 29, 2018: member
const int nHeight = pindexPrev == nullptr ? 0 : pindexPrev->nHeight + 1; -
kallewoof commented at 4:53 AM on November 29, 2018: member
Yeah, that pretty much proves it. It could change in the future, though, so I think the change is still warranted. It also plugs a static analyzer warning about null dereferencing, so there is that.
- kallewoof force-pushed on Nov 29, 2018
-
luke-jr commented at 4:57 AM on November 29, 2018: member
If it changes in the future, your modification here is a security vulnerability, since the block must be checked with the correct min locktime.
- kallewoof force-pushed on Nov 29, 2018
- kallewoof renamed this:
validation: do not break assumption that pindexPrev may be null
validation: assert that pindexPrev is non-null when required
on Nov 29, 2018 -
kallewoof commented at 5:01 AM on November 29, 2018: member
@luke-jr I changed the approach and am now asserting that
pindexPrevis non-null for the case where the lock time flags haveLOCKTIME_MEDIAN_TIME_PAST. That seems more aligned with your reasoning, I think, and I agree makes more sense in this case. -
luke-jr commented at 5:10 AM on November 29, 2018: member
I guess that looks okay, although I found the logic relatively hard to follow.
-
kallewoof commented at 5:15 AM on November 29, 2018: member
Actually, I can just move it into the if block above. Doing.
-
validation: assert that pindexPrev is non-null when required fbaaf782ce
- kallewoof force-pushed on Nov 29, 2018
-
luke-jr commented at 5:19 AM on November 29, 2018: member
utACK
-
practicalswift commented at 7:19 AM on November 29, 2018: contributor
utACK fbaaf782cea54dc433e72129ee1088b3169cdfd4
Very nice to get rid of this warning and thereby increase the signal-to-noise in static analyzer output! Explicit assumptions are better than implicit assumptions. Thanks!
-
promag commented at 8:05 AM on November 29, 2018: member
utACK fbaaf782.
-
promag commented at 11:49 AM on November 29, 2018: member
@kallewoof yeah, it doesn't improve this patch, I've updated my comment shortly after, but now I've removed the suggestion.
-
kallewoof commented at 10:46 PM on November 29, 2018: member
Gotcha!
-
Empact commented at 11:23 AM on December 4, 2018: member
utACK fbaaf782cea54dc433e72129ee1088b3169cdfd4
-
MarcoFalke commented at 4:38 PM on December 4, 2018: member
utACK fbaaf782cea54dc433e72129ee1088b3169cdfd4
-
jonasschnelli commented at 11:15 PM on December 9, 2018: contributor
utACK fbaaf782cea54dc433e72129ee1088b3169cdfd4
- laanwj merged this on Dec 13, 2018
- laanwj closed this on Dec 13, 2018
- laanwj referenced this in commit 20c54eef6e on Dec 13, 2018
- kallewoof deleted the branch on Dec 13, 2018
- PastaPastaPasta referenced this in commit 7a76765026 on Jun 27, 2021
- PastaPastaPasta referenced this in commit cd5cfd5294 on Jun 28, 2021
- PastaPastaPasta referenced this in commit 5092d7c97b on Jun 29, 2021
- PastaPastaPasta referenced this in commit a1f4a33785 on Jul 1, 2021
- PastaPastaPasta referenced this in commit 0b3de642bf on Jul 1, 2021
- PastaPastaPasta referenced this in commit b080b6e791 on Jul 1, 2021
- UdjinM6 referenced this in commit 84e5945963 on Jul 5, 2021
- PastaPastaPasta referenced this in commit eb15055000 on Jul 8, 2021
- MarcoFalke locked this on Sep 8, 2021