Replace memset with memset_s #23034

issue ghost opened this issue on September 19, 2021
  1. ghost commented at 4:56 AM on September 19, 2021: none

    I was watching this video: https://www.youtube.com/watch?v=gHGMDFm2MVs in which it is suggested to use memset_s() to avoid any issues because of compiler optimizations.

    image

    Also explained here: https://stackoverflow.com/questions/56565539/memset-s-what-does-the-standard-mean-with-this-piece-of-text

    It is used at lot of places: https://github.com/search?l=&q=memset+repo%3Abitcoin%2Fbitcoin&type=code

    Should we replace it with memset_s() ?

  2. yesbox commented at 2:33 PM on September 19, 2021: none

    Bitcoin uses the memory_cleanse function in its stead.

  3. sipa commented at 2:43 PM on September 19, 2021: member

    The memset_s function is defined in C11. Bitcoin Core isn't written in C, but in C++. No C++ standard to date includes such a function.

    Furthermore, it's an optional part of C11 which most compilers haven't implemented even; specifically, none of the compilers used for Bitcoin Core's release builds support it.

    Lastly, Bitcoin Core has its own (best effort) solution to clearing sensitive memory: an ad-hoc implemented memory_cleanse function which uses a technique to avoid being optimized away. We certainly wouldn't want all memset calls to be replaced with such a security-hardened version; most uses of memory setting are not used for clearing sensitive data.

  4. unknown closed this on Sep 19, 2021

  5. fanquake locked this on Sep 23, 2021
Contributors

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-17 15:14 UTC

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