Skip to content

Commit

Permalink
* ssp.c (__guard_setup): For Windows, use approved
Browse files Browse the repository at this point in the history
       methods to get a suitable random number for the stack
       check guard rather than reading /dev/random.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@220559 138bc75d-0d04-0410-961f-82ee72b054a4
  • Loading branch information
law committed Feb 10, 2015
1 parent 675f181 commit 19fef16
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
7 changes: 7 additions & 0 deletions libssp/ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
2015-02-09 Georg Koppen <gk@torproject.org>

* ssp.c: Conditionally include <windows.h>
(__guard_setup): For Windows, use approved methods to get
a suitable random number for the stack check guard rather
than reading /dev/random.

2015-01-22 Matthias Klose <doko@ubuntu.com>

* gets-chk.c: Declare prototype for gets in C11 mode.
Expand Down
16 changes: 16 additions & 0 deletions libssp/ssp.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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)
{
Expand All @@ -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;
Expand Down

0 comments on commit 19fef16

Please sign in to comment.