diff options
author | Ben Noordhuis <info@bnoordhuis.nl> | 2012-04-10 15:57:21 +0200 |
---|---|---|
committer | Ben Noordhuis <info@bnoordhuis.nl> | 2012-04-12 01:34:05 +0200 |
commit | 30e7fb7307011a3c8d2586d73817ec967a863647 (patch) | |
tree | 8d51607ed56bc08fe4222fae6e2cd02bc81d871d /deps/openssl/openssl/crypto/rand/randfile.c | |
parent | aa5961a445acbd2b533ef870eb19733be7b7ede5 (diff) | |
download | android-node-v8-30e7fb7307011a3c8d2586d73817ec967a863647.tar.gz android-node-v8-30e7fb7307011a3c8d2586d73817ec967a863647.tar.bz2 android-node-v8-30e7fb7307011a3c8d2586d73817ec967a863647.zip |
deps: upgrade openssl to 1.0.0f
Diffstat (limited to 'deps/openssl/openssl/crypto/rand/randfile.c')
-rw-r--r-- | deps/openssl/openssl/crypto/rand/randfile.c | 32 |
1 files changed, 17 insertions, 15 deletions
diff --git a/deps/openssl/openssl/crypto/rand/randfile.c b/deps/openssl/openssl/crypto/rand/randfile.c index 181056847e..bc7d9c5804 100644 --- a/deps/openssl/openssl/crypto/rand/randfile.c +++ b/deps/openssl/openssl/crypto/rand/randfile.c @@ -75,9 +75,7 @@ #ifndef NO_SYS_TYPES_H # include <sys/types.h> #endif -#ifdef MAC_OS_pre_X -# include <stat.h> -#else +#ifndef OPENSSL_NO_POSIX_IO # include <sys/stat.h> #endif @@ -111,12 +109,15 @@ int RAND_load_file(const char *file, long bytes) * if bytes == -1, read complete file. */ MS_STATIC unsigned char buf[BUFSIZE]; +#ifndef OPENSSL_NO_POSIX_IO struct stat sb; +#endif int i,ret=0,n; FILE *in; if (file == NULL) return(0); +#ifndef OPENSSL_NO_POSIX_IO #ifdef PURIFY /* struct stat can have padding and unused fields that may not be * initialized in the call to stat(). We need to clear the entire @@ -125,9 +126,9 @@ int RAND_load_file(const char *file, long bytes) */ memset(&sb, 0, sizeof(sb)); #endif - if (stat(file,&sb) < 0) return(0); RAND_add(&sb,sizeof(sb),0.0); +#endif if (bytes == 0) return(ret); #ifdef OPENSSL_SYS_VMS @@ -136,14 +137,16 @@ int RAND_load_file(const char *file, long bytes) in=fopen(file,"rb"); #endif if (in == NULL) goto err; -#if defined(S_ISBLK) && defined(S_ISCHR) - if (S_ISBLK(sb.st_mode) || S_ISCHR(sb.st_mode)) { +#if defined(S_IFBLK) && defined(S_IFCHR) && !defined(OPNESSL_NO_POSIX_IO) + if (sb.st_mode & (S_IFBLK | S_IFCHR)) { /* this file is a device. we don't want read an infinite number * of bytes from a random device, nor do we want to use buffered * I/O because we will waste system entropy. */ bytes = (bytes == -1) ? 2048 : bytes; /* ok, is 2048 enough? */ +#ifndef OPENSSL_NO_SETVBUF_IONBF setvbuf(in, NULL, _IONBF, 0); /* don't do buffered reads */ +#endif /* ndef OPENSSL_NO_SETVBUF_IONBF */ } #endif for (;;) @@ -179,6 +182,7 @@ int RAND_write_file(const char *file) int i,ret=0,rand_err=0; FILE *out = NULL; int n; +#ifndef OPENSSL_NO_POSIX_IO struct stat sb; i=stat(file,&sb); @@ -194,14 +198,16 @@ int RAND_write_file(const char *file) } #endif } +#endif -#if defined(O_CREAT) && !defined(OPENSSL_SYS_WIN32) && !defined(OPENSSL_SYS_VMS) +#if defined(O_CREAT) && !defined(OPENSSL_NO_POSIX_IO) && !defined(OPENSSL_SYS_VMS) { - /* For some reason Win32 can't write to files created this way */ - +#ifndef O_BINARY +#define O_BINARY 0 +#endif /* chmod(..., 0600) is too late to protect the file, * permissions should be restrictive from the start */ - int fd = open(file, O_CREAT, 0600); + int fd = open(file, O_WRONLY|O_CREAT|O_BINARY, 0600); if (fd != -1) out = fdopen(fd, "wb"); } @@ -266,7 +272,6 @@ const char *RAND_file_name(char *buf, size_t size) { char *s=NULL; #ifdef __OpenBSD__ - int ok = 0; struct stat sb; #endif @@ -294,9 +299,6 @@ const char *RAND_file_name(char *buf, size_t size) BUF_strlcat(buf,"/",size); #endif BUF_strlcat(buf,RFILE,size); -#ifdef __OpenBSD__ - ok = 1; -#endif } else buf[0] = '\0'; /* no file name */ @@ -310,7 +312,7 @@ const char *RAND_file_name(char *buf, size_t size) * to something hopefully decent if that isn't available. */ - if (!ok) + if (!buf[0]) if (BUF_strlcpy(buf,"/dev/arandom",size) >= size) { return(NULL); } |