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
  1. kallewoof commented at 4:19 AM on November 29, 2018: member

    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.

  2. 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.

  3. fanquake added the label Validation on Nov 29, 2018
  4. kallewoof commented at 4:29 AM on November 29, 2018: member

    That's a good point. Is that the only case ContextualCheckBlock is called with pindexPrev == nullptr? (When block is the genesis block)

  5. luke-jr commented at 4:32 AM on November 29, 2018: member
         const int nHeight = pindexPrev == nullptr ? 0 : pindexPrev->nHeight + 1;
    
  6. 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.

  7. kallewoof force-pushed on Nov 29, 2018
  8. 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.

  9. kallewoof force-pushed on Nov 29, 2018
  10. 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
  11. kallewoof commented at 5:01 AM on November 29, 2018: member

    @luke-jr I changed the approach and am now asserting that pindexPrev is non-null for the case where the lock time flags have LOCKTIME_MEDIAN_TIME_PAST. That seems more aligned with your reasoning, I think, and I agree makes more sense in this case.

  12. 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.

  13. kallewoof commented at 5:15 AM on November 29, 2018: member

    Actually, I can just move it into the if block above. Doing.

  14. validation: assert that pindexPrev is non-null when required fbaaf782ce
  15. kallewoof force-pushed on Nov 29, 2018
  16. luke-jr commented at 5:19 AM on November 29, 2018: member

    utACK

  17. 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!

  18. promag commented at 8:05 AM on November 29, 2018: member

    utACK fbaaf782.

  19. kallewoof commented at 8:10 AM on November 29, 2018: member

    @promag Maybe I'm not looking closely enough -- how does that improve the patch?

  20. 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.

  21. kallewoof commented at 10:46 PM on November 29, 2018: member

    Gotcha!

  22. Empact commented at 11:23 AM on December 4, 2018: member

    utACK fbaaf782cea54dc433e72129ee1088b3169cdfd4

  23. MarcoFalke commented at 4:38 PM on December 4, 2018: member

    utACK fbaaf782cea54dc433e72129ee1088b3169cdfd4

  24. jonasschnelli commented at 11:15 PM on December 9, 2018: contributor

    utACK fbaaf782cea54dc433e72129ee1088b3169cdfd4

  25. laanwj merged this on Dec 13, 2018
  26. laanwj closed this on Dec 13, 2018

  27. laanwj referenced this in commit 20c54eef6e on Dec 13, 2018
  28. kallewoof deleted the branch on Dec 13, 2018
  29. PastaPastaPasta referenced this in commit 7a76765026 on Jun 27, 2021
  30. PastaPastaPasta referenced this in commit cd5cfd5294 on Jun 28, 2021
  31. PastaPastaPasta referenced this in commit 5092d7c97b on Jun 29, 2021
  32. PastaPastaPasta referenced this in commit a1f4a33785 on Jul 1, 2021
  33. PastaPastaPasta referenced this in commit 0b3de642bf on Jul 1, 2021
  34. PastaPastaPasta referenced this in commit b080b6e791 on Jul 1, 2021
  35. UdjinM6 referenced this in commit 84e5945963 on Jul 5, 2021
  36. PastaPastaPasta referenced this in commit eb15055000 on Jul 8, 2021
  37. MarcoFalke locked this on Sep 8, 2021

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-04-14 18:15 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me