build warning: fortify memcpy #23638

issue jsarenik opened this issue on November 30, 2021
  1. jsarenik commented at 9:35 PM on November 30, 2021: none

    <!-- This issue tracker is only for technical issues related to Bitcoin Core. General bitcoin questions and/or support requests are best directed to the Bitcoin StackExchange at https://bitcoin.stackexchange.com. For reporting security issues, please read instructions at https://bitcoincore.org/en/contact/. If the node is "stuck" during sync or giving "block checksum mismatch" errors, please ensure your hardware is stable by running memtest and observe CPU temperature with a load-test tool such as linpack before creating an issue! -->

    <!-- Describe the issue -->

    This is just a warning, but want to make a note here.

      CXX      libbitcoin_server_a-signet.o
    In file included from /usr/include/c++/10.3.1/cstring:42,
                     from ./uint256.h:10,
                     from ./consensus/params.h:9,
                     from ./signet.h:8,
                     from signet.cpp:5:
    In function 'void* memcpy(void*, const void*, size_t)',
        inlined from 'void CVectorWriter::write(const char*, size_t)' at ./streams.h:102:19,
        inlined from 'void base_blob<BITS>::Serialize(Stream&) const [with Stream = CVectorWriter; unsigned int BITS = 256]' at ./uint256.h:99:16,
        inlined from 'static std::optional<SignetTxs> SignetTxs::Create(const CBlock&, const CScript&)' at ./serialize.h:670:16:
    /usr/include/fortify/string.h:53:25: warning: 'void* __builtin_memcpy(void*, const void*, long unsigned int)' writing between 1 and 32 bytes into a region of size 0 overflows the destination [-Wstringop-overflow=]
       53 |  return __builtin_memcpy(__od, __os, __n);
          |         ~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~
    

    Expected behavior

    Clean happy compilation, something like this which comes from later output:

    ...
      CXX      wallet/libbitcoin_wallet_a-db.o
      CXX      wallet/libbitcoin_wallet_a-dump.o
      CXX      wallet/libbitcoin_wallet_a-external_signer_scriptpubkeyman.o
      CXX      wallet/libbitcoin_wallet_a-feebumper.o
      CXX      wallet/libbitcoin_wallet_a-fees.o
      CXX      wallet/libbitcoin_wallet_a-interfaces.o
    ...
    

    <!--- What behavior did you expect? -->

    Actual behavior

    Warnings during make.

    <!--- What was the actual behavior (provide screenshots if the issue is GUI-related)? -->

    To reproduce

    # On Alpine Linux (musl-libc)
    export CFLAGS="-pipe -s -march=native -mtune=native -O3"
    export LDFLAGS="-s -no-pie"
    
    test -x ./configure || ./autogen.sh
    ./configure \
      --without-gui \
      --with-incompatible-bdb \
      --disable-tests \
      --disable-bench \
      --disable-zmq \
      --disable-hardening \
      CFLAGS="$CFLAGS" \
      CXXFLAGS="$CFLAGS" \
      LDFLAGS="$LDFLAGS"
    make prefix=$HOME/bitcoin-latest install
    

    <!--- How reliably can you reproduce the issue, what are the steps to do so? -->

    System information

    Alpine Linux (musl-libc x86_64)

    $ uname -mr
    5.10.61-0-lts x86_64
    

    <!-- What version of Bitcoin Core are you using, where did you get it (website, self-compiled, etc)? -->

    Self-compiled Bitcoin Core exactly from jsarenik/bitcoin@878d8e1c0

    <!-- What type of machine are you observing the error on (OS/CPU and disk type)? -->

    <!-- GUI-related issue? What is your operating system and its version? If Linux, what is your desktop environment and graphical shell? -->

    <!-- Any extra information that might be useful in the debugging process. -->

    <!--- This is normally the contents of a `debug.log` or `config.log` file. Raw text or a link to a pastebin type site are preferred. -->

    This warning was experienced while compiling version of bitcoin to test #23531 while also rebasing #22563 on top of it and also Alpine Linux locales patch.

    All the rebasing was trivial and maybe the warning is showing for longer but now I noticed it for the first time.

  2. jsarenik added the label Bug on Nov 30, 2021
  3. MarcoFalke commented at 12:53 PM on December 13, 2021: member

    Looks like a compiler bug

  4. MarcoFalke added the label Upstream on Dec 13, 2021
  5. MarcoFalke commented at 12:54 PM on December 13, 2021: member

    For reference, the function is:

        void write(const char* pch, size_t nSize)
        {
            assert(nPos <= vchData.size());
            size_t nOverwrite = std::min(nSize, vchData.size() - nPos);
            if (nOverwrite) {
                memcpy(vchData.data() + nPos, reinterpret_cast<const unsigned char*>(pch), nOverwrite);
            }
            if (nOverwrite < nSize) {
                vchData.insert(vchData.end(), reinterpret_cast<const unsigned char*>(pch) + nOverwrite, reinterpret_cast<const unsigned char*>(pch) + nSize);
            }
            nPos += nSize;
        }
    
  6. fanquake commented at 1:42 PM on December 13, 2021: member

    Looks like a compiler bug

    Yes I think so. Reproduced with GCC 10.3.1 (on Alpine), with -O3, no warning with -O2. Possibly https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94335 or related to https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92955.

    Not much we can do here, other than suggest you up/downgrade to a non-buggy compiler.

    Going to close for now.

  7. fanquake closed this on Dec 13, 2021

  8. DrahtBot locked this on Dec 13, 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-13 21:14 UTC

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