Improve explicit_bzero implementation

Using the weak symbol explicit_bzero_hook does not work if LTO is
enabled. Instead avoid memset optimizations using an asm memory
barrier.

Use a fallback implementation where the memory is zeroed through
volatile.
This commit is contained in:
David Carlier 2017-12-09 22:28:21 +00:00 committed by Nikita Popov
parent ff7c9990d4
commit e835e3c132

View File

@ -30,15 +30,18 @@
#include <string.h>
__attribute__((weak)) void
__explicit_bzero_hook(void *dst, size_t siz)
{
}
PHPAPI void php_explicit_bzero(void *dst, size_t siz)
{
#ifdef __GNUC__
memset(dst, 0, siz);
__explicit_bzero_hook(dst, siz);
asm __volatile__("" :: "r"(dst) : "memory");
#else
size_t i = 0;
volatile unsigned char *buf = (volatile unsigned char *)dst;
for (; i < siz; i ++)
buf[i] = 0;
#endif
}
#endif
/*