From: Andy Polyakov Date: Fri, 14 Jan 2005 16:19:47 +0000 (+0000) Subject: O_NOFOLLOW is not appropriate when opening /dev/* entries on Solaris. X-Git-Tag: OpenSSL_0_9_7f~45 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=adeb20b6b763ba96e7f2b6f6bf1fad50a55dbcb1;p=openssl O_NOFOLLOW is not appropriate when opening /dev/* entries on Solaris. PR: 998 --- diff --git a/crypto/rand/rand_unix.c b/crypto/rand/rand_unix.c index f5165f1326..9376554fae 100644 --- a/crypto/rand/rand_unix.c +++ b/crypto/rand/rand_unix.c @@ -120,6 +120,7 @@ #include #include #include +#include #include #include #include @@ -151,9 +152,9 @@ int RAND_poll(void) int n = 0; #endif #ifdef DEVRANDOM - static const char *randomfiles[] = { DEVRANDOM, NULL }; - const char **randomfile = NULL; - int fd; + static const char *randomfiles[] = { DEVRANDOM }; + struct stat randomstats[sizeof(randomfiles)/sizeof(randomfiles[0])]; + int fd,i; #endif #ifdef DEVRANDOM_EGD static const char *egdsockets[] = { DEVRANDOM_EGD, NULL }; @@ -161,13 +162,14 @@ int RAND_poll(void) #endif #ifdef DEVRANDOM + memset(randomstats,0,sizeof(randomstats)); /* Use a random entropy pool device. Linux, FreeBSD and OpenBSD * have this. Use /dev/urandom if you can as /dev/random may block * if it runs out of random entries. */ - for (randomfile = randomfiles; *randomfile && n < ENTROPY_NEEDED; randomfile++) + for (i=0; i= 0) { struct timeval t = { 0, 10*1000 }; /* Spend 10ms on each file. */ - int r; + int r,j; fd_set fset; + struct stat *st=&randomstats[i]; + + /* Avoid using same input... Used to be O_NOFOLLOW + * above, but it's not universally appropriate... */ + if (fstat(fd,st) != 0) { close(fd); continue; } + for (j=0;jst_ino && + randomstats[j].st_dev==st->st_dev) + break; + } + if (j