Avoid undefined behavior using CFlatData in CScript serialization #4293

pull laanwj wants to merge 1 commits into bitcoin:master from laanwj:2014_06_flatdata_vector changing 2 files +38 −4
  1. laanwj commented at 8:19 AM on June 5, 2014: member

    &vch[vch.size()] and even &vch[0] on vectors can cause assertion errors with VC in debug mode. This is the problem mentioned in #4239. The deeper problem with this is that we rely on undefined behavior.

    I added begin_ptr and end_ptr as separate functions as I imagine they will be useful in more places. @LongShao007 this was your issue, can you help test?

  2. LongShao007 commented at 12:23 PM on June 8, 2014: contributor

    The test is passed. I copy the files ( script.h and serialize.h ) to my VC project, modify the code, do the white testing, debug the program many times, don't cause assertion errors ( vector subscript out of range ) .

  3. laanwj commented at 8:45 AM on June 10, 2014: member

    Thanks for testing @LongShao007

  4. laanwj added this to the milestone 0.10.0 on Jun 19, 2014
  5. petertodd commented at 1:33 PM on June 21, 2014: contributor

    ACK

  6. sipa commented at 2:11 PM on June 21, 2014: member

    Untested ACK.

  7. BitcoinPullTester commented at 1:41 AM on June 23, 2014: none

    Automatic sanity-testing: PASSED, see http://jenkins.bluematt.me/pull-tester/p4293_2ede43ebe0e87f982747feaec62aeefaf12c3a41/ 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.

  8. Avoid undefined behavior using CFlatData in CScript serialization
    `&vch[vch.size()]` and even `&vch[0]` on vectors can cause assertion
    errors with VC in debug mode. This is the problem mentioned in #4239.
    The deeper problem with this is that we rely on undefined behavior.
    
    - Add `begin_ptr` and `end_ptr` functions that get the beginning and end
      pointer of vector in a reliable way that copes with empty vectors and
      doesn't reference outside the vector
    (see https://stackoverflow.com/questions/1339470/how-to-get-the-address-of-the-stdvector-buffer-start-most-elegantly/1339767#1339767).
    - Add a convenience constructor to CFlatData that wraps a vector.
    
    I added `begin_ptr` and `end_ptr` as separate functions as I imagine
    they will be useful in more places.
    fa126effc2
  9. laanwj merged this on Jun 23, 2014
  10. laanwj closed this on Jun 23, 2014

  11. laanwj referenced this in commit 5459116d61 on Jun 23, 2014
  12. 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-13 18:15 UTC

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