aboutsummaryrefslogtreecommitdiff
path: root/libssp/ssp.c
diff options
context:
space:
mode:
authorGeorg Koppen <gk@torproject.org>2015-02-10 01:44:08 +0000
committerJeff Law <law@gcc.gnu.org>2015-02-09 18:44:08 -0700
commitadebb6e733c59da7c75051f27c47f38337d387ae (patch)
tree39c5991cbcd01a490e24d4ab4f3dfb455aa5485f /libssp/ssp.c
parent94a2f772f041cdbc3711aa8b7da8678fb206fa36 (diff)
downloadgcc-adebb6e733c59da7c75051f27c47f38337d387ae.zip
gcc-adebb6e733c59da7c75051f27c47f38337d387ae.tar.gz
gcc-adebb6e733c59da7c75051f27c47f38337d387ae.tar.bz2
ssp.c (__guard_setup): For Windows...
* ssp.c (__guard_setup): For Windows, use approved methods to get a suitable random number for the stack check guard rather than reading /dev/random. From-SVN: r220559
Diffstat (limited to 'libssp/ssp.c')
-rw-r--r--libssp/ssp.c16
1 files changed, 16 insertions, 0 deletions
diff --git a/libssp/ssp.c b/libssp/ssp.c
index 96adf17..38e3ec8 100644
--- a/libssp/ssp.c
+++ b/libssp/ssp.c
@@ -55,6 +55,7 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
/* 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>
# define _PATH_TTY "CONOUT$"
#else
# define _PATH_TTY "/dev/tty"
@@ -75,6 +76,20 @@ __guard_setup (void)
if (__stack_chk_guard != 0)
return;
+#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
fd = open ("/dev/urandom", O_RDONLY);
if (fd != -1)
{
@@ -85,6 +100,7 @@ __guard_setup (void)
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;