/* Stack protector support.
- Copyright (C) 2005-2013 Free Software Foundation, Inc.
+ Copyright (C) 2005-2020 Free Software Foundation, Inc.
This file is part of GCC.
/* Native win32 apps don't know about /dev/tty but can print directly
to the console using "CONOUT$" */
#if defined (_WIN32) && !defined (__CYGWIN__)
+#include <windows.h>
+#include <wincrypt.h>
# define _PATH_TTY "CONOUT$"
#else
# define _PATH_TTY "/dev/tty"
__guard_setup (void)
{
unsigned char *p;
- int fd;
if (__stack_chk_guard != 0)
return;
- fd = open ("/dev/urandom", O_RDONLY);
+#if defined (_WIN32) && !defined (__CYGWIN__)
+ HCRYPTPROV hprovider = 0;
+ if (CryptAcquireContext(&hprovider, NULL, NULL, PROV_RSA_FULL,
+ CRYPT_VERIFYCONTEXT | CRYPT_SILENT))
+ {
+ if (CryptGenRandom(hprovider, sizeof (__stack_chk_guard),
+ (BYTE *)&__stack_chk_guard) && __stack_chk_guard != 0)
+ {
+ CryptReleaseContext(hprovider, 0);
+ return;
+ }
+ CryptReleaseContext(hprovider, 0);
+ }
+#else
+ int fd = open ("/dev/urandom", O_RDONLY);
if (fd != -1)
{
ssize_t size = read (fd, &__stack_chk_guard,
return;
}
+#endif
/* If a random generator can't be used, the protector switches the guard
to the "terminator canary". */
p = (unsigned char *) &__stack_chk_guard;
#ifdef HAVE_SYSLOG_H
/* Only send the error to syslog if there was no tty available. */
else
- syslog (LOG_CRIT, msg3);
+ syslog (LOG_CRIT, "%s", msg3);
#endif /* HAVE_SYSLOG_H */
/* Try very hard to exit. Note that signals may be blocked preventing