diff options
| author | Gary Ching-Pang Lin <glin@suse.com> | 2015-07-13 11:58:44 +0800 |
|---|---|---|
| committer | Peter Jones <pjones@redhat.com> | 2015-07-28 11:46:38 -0400 |
| commit | 4ac84f8673eb7f3e5b98226aabe21f3e3111c7db (patch) | |
| tree | 2fb3d9dd667c772fae5f87fa61e1501cf12da0ce /Cryptlib/OpenSSL/crypto/rand/randfile.c | |
| parent | db142ce288a63db2e8f7858ba7564158cc7a64e5 (diff) | |
| download | efi-boot-shim-4ac84f8673eb7f3e5b98226aabe21f3e3111c7db.tar.gz efi-boot-shim-4ac84f8673eb7f3e5b98226aabe21f3e3111c7db.zip | |
Update openssl to 1.0.2d
Also update Cryptlib to edk2 r17731
Signed-off-by: Gary Ching-Pang Lin <glin@suse.com>
Diffstat (limited to 'Cryptlib/OpenSSL/crypto/rand/randfile.c')
| -rw-r--r-- | Cryptlib/OpenSSL/crypto/rand/randfile.c | 46 |
1 files changed, 26 insertions, 20 deletions
diff --git a/Cryptlib/OpenSSL/crypto/rand/randfile.c b/Cryptlib/OpenSSL/crypto/rand/randfile.c index 3feca3d5..9537c56a 100644 --- a/Cryptlib/OpenSSL/crypto/rand/randfile.c +++ b/Cryptlib/OpenSSL/crypto/rand/randfile.c @@ -57,7 +57,9 @@ */ /* We need to define this to get macros like S_IFBLK and S_IFCHR */ -#define _XOPEN_SOURCE 500 +#if !defined(OPENSSL_SYS_VXWORKS) +# define _XOPEN_SOURCE 500 +#endif #include <errno.h> #include <stdio.h> @@ -75,10 +77,9 @@ #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> +# include <fcntl.h> #endif #ifdef _WIN32 @@ -117,14 +118,17 @@ int RAND_load_file(const char *file, long bytes) */ 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); -#ifdef PURIFY +#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 @@ -132,11 +136,11 @@ int RAND_load_file(const char *file, long bytes) * applications such as Valgrind. */ memset(&sb, 0, sizeof(sb)); -#endif - +# endif if (stat(file, &sb) < 0) return (0); RAND_add(&sb, sizeof(sb), 0.0); +#endif if (bytes == 0) return (ret); @@ -147,15 +151,17 @@ int RAND_load_file(const char *file, long bytes) #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(OPENSSL_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 (;;) { @@ -191,11 +197,12 @@ 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); if (i != -1) { -#if defined(S_ISBLK) && defined(S_ISCHR) +# if defined(S_ISBLK) && defined(S_ISCHR) if (S_ISBLK(sb.st_mode) || S_ISCHR(sb.st_mode)) { /* * this file is a device. we don't write back to it. we @@ -205,17 +212,20 @@ int RAND_write_file(const char *file) */ return (1); } -#endif +# endif } -#if defined(O_CREAT) && !defined(OPENSSL_SYS_WIN32) && !defined(OPENSSL_SYS_VMS) - { - /* For some reason Win32 can't write to files created this way */ +#endif +#if defined(O_CREAT) && !defined(OPENSSL_NO_POSIX_IO) && !defined(OPENSSL_SYS_VMS) + { +# 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"); } @@ -279,7 +289,6 @@ const char *RAND_file_name(char *buf, size_t size) { char *s = NULL; #ifdef __OpenBSD__ - int ok = 0; struct stat sb; #endif @@ -302,9 +311,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 */ } @@ -318,7 +324,7 @@ const char *RAND_file_name(char *buf, size_t size) * available. */ - if (!ok) + if (!buf[0]) if (BUF_strlcpy(buf, "/dev/arandom", size) >= size) { return (NULL); } |
