[uClibc-cvs] CVS uClibc/libc/sysdeps/linux/common
CVS User solar
solar at codepoet.org
Tue Feb 8 17:37:28 UTC 2005
Update of /var/cvs/uClibc/libc/sysdeps/linux/common
In directory nail:/tmp/cvs-serv17805
Modified Files:
ssp.c
Log Message:
- ssp updates 1/NN today
--- /var/cvs/uClibc/libc/sysdeps/linux/common/ssp.c 2005/01/11 17:01:53 1.6
+++ /var/cvs/uClibc/libc/sysdeps/linux/common/ssp.c 2005/02/08 17:37:27 1.7
@@ -1,6 +1,6 @@
/*
* Distributed under the terms of the GNU General Public License v2
- * $Header: /var/cvs/uClibc/libc/sysdeps/linux/common/ssp.c,v 1.6 2005/01/11 17:01:53 vapier Exp $
+ * $Header: /var/cvs/uClibc/libc/sysdeps/linux/common/ssp.c,v 1.7 2005/02/08 17:37:27 solar Exp $
*
* This is a modified version of Hiroaki Etoh's stack smashing routines
* implemented for glibc.
@@ -29,7 +29,7 @@
#include <sys/un.h>
#include <sys/syslog.h>
#include <sys/time.h>
-#ifdef HAVE_DEV_ERANDOM
+#ifdef __SSP_USE_ERANDOM__
#include <sys/sysctl.h>
#endif
@@ -48,39 +48,33 @@
size_t size;
struct timeval tv;
-#ifdef HAVE_DEV_ERANDOM
- int mib[3];
-#endif
-
if (__guard != 0UL)
return;
#ifndef __SSP_QUICK_CANARY__
-#ifdef HAVE_DEV_ERANDOM
- /* Random is another depth in Linux, hence an array of 3. */
+#ifdef __SSP_USE_ERANDOM__
+ int i=0, mib[3];
mib[0] = CTL_KERN;
mib[1] = KERN_RANDOM;
mib[2] = RANDOM_ERANDOM;
- size = sizeof(unsigned long);
- if (__sysctl(mib, 3, &__guard, &size, NULL, 0) != (-1))
- if (__guard != 0UL)
- return;
-#endif
- /*
- * Attempt to open kernel pseudo random device if one exists before
- * opening urandom to avoid system entropy depletion.
- */
+ for (i = 0; i < sizeof(__guard) / 4; i++) {
+ size = sizeof(unsigned long);
+ if (sysctl(mib, 3, &__guard, &size, NULL, 0) == -1)
+ break;
+ }
+ if (i < sizeof(__guard) / 4)
+#endif
{
- int fd;
+ int fd=0;
-#ifdef HAVE_DEV_ERANDOM
- if ((fd = open("/dev/erandom", O_RDONLY)) == (-1))
+#ifdef __SSP_USE_ERANDOM__
+ if ((fd = __libc_open("/dev/erandom", O_RDONLY)) == (-1))
#endif
- fd = open("/dev/urandom", O_RDONLY);
+ fd = __libc_open("/dev/urandom", O_RDONLY);
if (fd != (-1)) {
- size = read(fd, (char *) &__guard, sizeof(__guard));
- close(fd);
+ size = __libc_read(fd, (char *) &__guard, sizeof(__guard));
+ __libc_close(fd);
if (size == sizeof(__guard))
return;
}
@@ -90,7 +84,7 @@
__guard = 0xFF0A0D00UL;
/* Everything failed? Or we are using a weakened model of the
- * terminator canary */
+ * terminator canary */
gettimeofday(&tv, NULL);
__guard ^= tv.tv_usec ^ tv.tv_sec;
@@ -106,13 +100,13 @@
sigfillset(&mask);
sigdelset(&mask, SSP_SIGTYPE); /* Block all signal handlers */
- sigprocmask(SIG_BLOCK, &mask, NULL); /* except SIGABRT */
+ sigprocmask(SIG_BLOCK, &mask, NULL); /* except SSP_SIGTYPE */
- /* print error message to stderr and syslog */
+ /* Print error message to stderr and syslog */
fprintf(stderr, "%s%s%s()\n", __progname, message, func);
syslog(LOG_INFO, "%s%s%s()", __progname, message, func);
- /* Make sure the default handler is associated with the our signal handler */
+ /* Make the default handler associated with the signal handler */
memset(&sa, 0, sizeof(struct sigaction));
sigfillset(&sa.sa_mask); /* Block all signals */
sa.sa_flags = 0;
More information about the uClibc-cvs
mailing list