Undefined behavior in AutoFile::write (gcc only) #28761

issue dergoegge openend this issue on October 31, 2023
  1. dergoegge commented at 1:03 pm on October 31, 2023: member
     0$ CC=gcc CXX=g++ ./configure --with-sanitizers=undefined && make
     1$ export UBSAN_OPTIONS=print_stacktrace=1:halt_on_error=1:report_error_type=1
     2$ FUZZ=utxo_snapshot ./src/test/fuzz/fuzz ../qa-assets/fuzz_seed_corpus/utxo_snapshot/
     3streams.cpp:48:24: runtime error: null pointer passed as argument 1, which is declared to never be null
     4    [#0](/bitcoin-bitcoin/0/) 0x5634737bcdc0 in AutoFile::write(Span<std::byte const>) src/streams.cpp:48
     5    [#1](/bitcoin-bitcoin/1/) 0x5634749e553b in void Serialize<AutoFile, unsigned char const>(AutoFile&, Span<unsigned char const>) serialize.h:288
     6    [#2](/bitcoin-bitcoin/2/) 0x5634749e553b in AutoFile& AutoFile::operator<< <Span<unsigned char const> >(Span<unsigned char const> const&) streams.h:527
     7    [#3](/bitcoin-bitcoin/3/) 0x5634749e553b in utxo_snapshot_fuzz_target test/fuzz/utxo_snapshot.cpp:45
     8    ...
     9$ ./src/test/test_bitcoin --run_test="net_tests"
    10streams.cpp:49:24: runtime error: null pointer passed as argument 1, which is declared to never be null
    11    [#0](/bitcoin-bitcoin/0/) 0x55613837a3ee in AutoFile::write(Span<std::byte const>) src/streams.cpp:49
    12    [#1](/bitcoin-bitcoin/1/) 0x55613b9747cc in void Serialize<AutoFile, unsigned char const>(AutoFile&, Span<unsigned char const>) serialize.h:288
    13    [#2](/bitcoin-bitcoin/2/) 0x55613b9747cc in AutoFile& AutoFile::operator<< <Span<unsigned char const> >(Span<unsigned char const> const&) streams.h:527
    14    [#3](/bitcoin-bitcoin/3/) 0x55613b9747cc in CaptureMessageToFile src/net.cpp:3885
    

    This is harmless since the spans passed to AutoFile::write will always be of size 0 in this case.

  2. maflcko commented at 4:49 pm on October 31, 2023: member
    I think this is a “bug” in gcc that should be fixed upstream. See also the related discussion in https://reviews.llvm.org/D86993
  3. maflcko added the label Upstream on Oct 31, 2023
  4. maflcko added the label Tests on Oct 31, 2023
  5. maflcko commented at 3:47 pm on November 2, 2023: member
    Also, a suppression can be added in the meantime, if anyone is using g++
  6. willcl-ark closed this on Oct 14, 2024


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: 2024-12-21 15:12 UTC

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