Avoid signed arithmetic undefined behaviour #3799

pull vegard wants to merge 2 commits into bitcoin:master from vegard:undefined-behaviour changing 2 files +11 −5
  1. vegard commented at 12:42 AM on March 5, 2014: contributor

    These two places look like they obviously rely on undefined behaviour to me. See e.g. http://blog.regehr.org/archives/213 for a primer. In short, the compiler is free to do pretty much whatever it wants if the sum of two signed integers overflows. This includes deleting your wallet file, stopping the process, or simply optimising out the check entirely.

    Please review carefully.

  2. Avoid signed arithmetic undefined behaviour in CheckInputs()
    While (a + b) is guaranteed to not overflow the 63 bits of int64_t if
    both MoneyRange(a) and MoneyRange(b), we should still not compute it
    before checking that these conditions hold, since that could lead to
    undefined behaviour.
    8323975340
  3. Avoid signed arithmetic undefined behaviour in CTransaction::GetValueOut() c5392e6b99
  4. BitcoinPullTester commented at 1:22 AM on March 5, 2014: none

    Automatic sanity-testing: PASSED, see http://jenkins.bluematt.me/pull-tester/c5392e6b9996ab46d6377091b9fae25801b25e37 for binaries and test log. This test script verifies pulls every time they are updated. It, however, dies sometimes and fails to test properly. If you are waiting on a test, please check timestamps to verify that the test.log is moving at http://jenkins.bluematt.me/pull-tester/current/ Contact BlueMatt on freenode if something looks broken.

  5. instagibbs commented at 5:28 PM on March 8, 2014: member

    I may be misunderstanding the link in connection with the changes. Could you define the scenario in which the original lines would trigger undefined behavior, and how your code fixes said situation?

  6. vegard commented at 6:40 PM on March 11, 2014: contributor

    On second look, it seems like the overflow is not possible after all and the values are already checked before reaching this point, in CheckTransaction(), anyway. Never mind, closing. Thanks.

  7. vegard closed this on Mar 11, 2014

  8. DrahtBot 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-22 00:15 UTC

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