3 ms·
are you sure that the padding is not zeroed by memset? [1] says that memset_s exists because it is not optimized away if it just clears a variable that will no
by MichaelMoser123 8y ago
are you sure that the padding is not zeroed by memset?
[1] says that memset_s exists because it is not optimized away if it just clears a variable that will not be used after the call (unlike memset)
On the other end: people who do this for security reasons say not to trust memset_s is 'an optional feature of c11 and not really portable' [2]
[1] https://en.cppreference.com/w/c/string/byte/memset https://en.cppreference.com/w/c/string/byte/memset
[2] https://www.cryptologie.net/article/419/zeroing-memory-compiler-optimizations-and-memset_s/ https://www.cryptologie.net/article/419/zeroing-memory-compi...
- saagarjha 8y agoI don't think memset is required to zero out any padding, because the effects of this are not observable.
- MichaelMoser123 8y agoThe function memset gets the length of the area to overwrite, how is it to know where the padding is?
- saagarjha 8y agoThe compiler knows the layout of your structure and can choose to elide memset calls or replace them with equivalent code.
- rurban 8y agoThis [2] is a dangerous post from a security guy, describing memset_s with just a compiler barrier as "secure". In the age of Spectre only a memset_s with a memory barrier is secure, and currently all memset_s but my safeclib memset_s are insecure. Esp. the ones with "Secure" in its name.
- deleted 8y ago[deleted]