Index: ssp.c =================================================================== RCS file: /var/cvs/uClibc/libc/sysdeps/linux/common/ssp.c,v retrieving revision 1.6 diff -u -b -B -w -p -r1.6 ssp.c --- ssp.c 11 Jan 2005 17:01:53 -0000 1.6 +++ ssp.c 8 Feb 2005 17:15:39 -0000 @@ -29,7 +29,7 @@ #include #include #include -#ifdef HAVE_DEV_ERANDOM +#ifdef __SSP_USE_ERANDOM__ #include #endif @@ -48,39 +48,33 @@ void __guard_setup(void) 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; + for (i = 0; i < sizeof(__guard) / 4; i++) { size = sizeof(unsigned long); - if (__sysctl(mib, 3, &__guard, &size, NULL, 0) != (-1)) - if (__guard != 0UL) - return; + if (sysctl(mib, 3, &__guard, &size, NULL, 0) == -1) + break; + } + if (i < sizeof(__guard) / 4) #endif - /* - * Attempt to open kernel pseudo random device if one exists before - * opening urandom to avoid system entropy depletion. - */ { - 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; } @@ -106,13 +100,13 @@ void __stack_smash_handler(char func[], 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;