[test] Avoid reading a potentially uninitialized variable in tx_invalid-test (transaction_tests.cpp) #9555

pull practicalswift wants to merge 1 commits into bitcoin:master from practicalswift:avoid-ub-in-tx_invalid-test changing 1 files +3 −1
  1. practicalswift commented at 7:45 PM on January 14, 2017: contributor

    Prior to this commit the err variable was not guaranteed to be set before the check ...

    BOOST_CHECK_MESSAGE(err != SCRIPT_ERR_OK, ScriptErrorString(err));
  2. practicalswift force-pushed on Jan 14, 2017
  3. MarcoFalke commented at 11:18 PM on January 14, 2017: member

    It is set one line before use, no?

    On Sat, Jan 14, 2017 at 8:45 PM, practicalswift notifications@github.com wrote:

    Prior to this commit the err variable was not guaranteed to set prior to the check ...

    BOOST_CHECK_MESSAGE(err != SCRIPT_ERR_OK, ScriptErrorString(err));

    ... triggering UB.

    You can view, comment on, or merge this pull request online at:

    #9555 Commit Summary

    • [test] Avoid undefined behaviour in tx_invalid-test (transaction_tests.cpp)

    File Changes

    Patch Links:

    — You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/bitcoin/bitcoin/pull/9555, or mute the thread https://github.com/notifications/unsubscribe-auth/AGGmvxdY6fMunnH-S0n2t9WF7XiZ_BQhks5rSSXkgaJpZM4LjuLa .

  4. practicalswift commented at 11:48 PM on January 14, 2017: contributor

    @MarcoFalke Not in the cases ...

    • tx.vin.size() == 0, or
    • !(CheckTransaction(tx, state) && state.IsValid())

    ... right? :-)

  5. fanquake added the label Tests on Jan 15, 2017
  6. practicalswift commented at 9:33 PM on January 15, 2017: contributor

    @MarcoFalke After re-reading your comment I think that you might be referring to err in the context of lines 172-175 whereas my PR is referring to err on lines 242-260. Is my interpretation correct? :-)

  7. practicalswift renamed this:
    [test] Avoid triggering undefined behaviour in tx_invalid-test (transaction_tests.cpp)
    [test] Avoid potentially reading an uninitialized variable in tx_invalid-test (transaction_tests.cpp)
    on Jan 15, 2017
  8. practicalswift force-pushed on Jan 15, 2017
  9. practicalswift renamed this:
    [test] Avoid potentially reading an uninitialized variable in tx_invalid-test (transaction_tests.cpp)
    [test] Avoid reading a potentially uninitialized variable in tx_invalid-test (transaction_tests.cpp)
    on Jan 15, 2017
  10. practicalswift force-pushed on Jan 15, 2017
  11. practicalswift force-pushed on Jan 15, 2017
  12. luke-jr commented at 11:03 PM on January 20, 2017: member

    It may be better to leave this be, so memory sanitizers and static analysis can detect cases where we fail to set it?

  13. practicalswift force-pushed on Jan 21, 2017
  14. practicalswift commented at 9:50 AM on January 21, 2017: contributor

    @luke-jr Good point about catching cases where we fail to set it. My suggestion is that we initialize to SCRIPT_ERR_OK. That will make sure that failures to set err are always detected since the test asserts that err != SCRIPT_ERR_OK. See updated version. Looks OK? :-)

  15. [test] Avoid reading a potentially uninitialized variable in tx_invalid-test
    Prior to this commit the err variable was not guaranteed to be set before
    the check ...
    
        BOOST_CHECK_MESSAGE(err != SCRIPT_ERR_OK, ScriptErrorString(err));
    8455e367fe
  16. practicalswift force-pushed on Jan 21, 2017
  17. MarcoFalke commented at 5:43 PM on January 22, 2017: member

    Indeed, I was reading the wrong lines of the file.

    utACK 8455e367fe79ff53ea81d283f3435e74b1633c88

  18. luke-jr commented at 8:46 PM on February 2, 2017: member

    That will still suppress compiler and analyser warnings of using unassigned values. Is there a way we can initialise it, yet tell the compiler/etc to treat the value as uninitialised still?

  19. practicalswift commented at 10:21 PM on February 2, 2017: contributor

    @luke-jr I don't know if that is possible and/or how to do it, but if possible I'll add such an annotation :-) Let me know if you find any info on how to achieve that

  20. MarcoFalke commented at 9:54 AM on March 6, 2017: member

    As long as the tests fail when the variable is not assigned the correct value in the code, all is fine.

  21. practicalswift commented at 9:56 AM on March 6, 2017: contributor

    @MarcoFalke Yes, that should be the case now :-)

  22. MarcoFalke merged this on Mar 7, 2017
  23. MarcoFalke closed this on Mar 7, 2017

  24. MarcoFalke referenced this in commit 19be26afe3 on Mar 7, 2017
  25. PastaPastaPasta referenced this in commit 91e4c8eb4d on Dec 30, 2018
  26. PastaPastaPasta referenced this in commit 56e30199cd on Dec 31, 2018
  27. PastaPastaPasta referenced this in commit e75e8db327 on Dec 31, 2018
  28. PastaPastaPasta referenced this in commit 3fa1734ff4 on Dec 31, 2018
  29. PastaPastaPasta referenced this in commit d7bc6e443a on Jan 2, 2019
  30. PastaPastaPasta referenced this in commit f8d1b2abe2 on Jan 2, 2019
  31. PastaPastaPasta referenced this in commit a11973e901 on Jan 3, 2019
  32. PastaPastaPasta referenced this in commit cb93de6463 on Jan 21, 2019
  33. PastaPastaPasta referenced this in commit 1fe5ef551f on Jan 27, 2019
  34. PastaPastaPasta referenced this in commit 1fb6fb1327 on Jan 29, 2019
  35. PastaPastaPasta referenced this in commit ace3c60a04 on Feb 5, 2019
  36. PastaPastaPasta referenced this in commit 31267f4c8a on Feb 5, 2019
  37. practicalswift deleted the branch on Apr 10, 2021
  38. DrahtBot locked this on Aug 16, 2022

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-16 15:15 UTC

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