diff options
Diffstat (limited to '')
| -rw-r--r-- | src/lib/libcrypto/rand/randfile.c | 22 |
1 files changed, 16 insertions, 6 deletions
diff --git a/src/lib/libcrypto/rand/randfile.c b/src/lib/libcrypto/rand/randfile.c index cfbec2ac1f..d88ee0d780 100644 --- a/src/lib/libcrypto/rand/randfile.c +++ b/src/lib/libcrypto/rand/randfile.c | |||
| @@ -56,6 +56,9 @@ | |||
| 56 | * [including the GNU Public Licence.] | 56 | * [including the GNU Public Licence.] |
| 57 | */ | 57 | */ |
| 58 | 58 | ||
| 59 | /* We need to define this to get macros like S_IFBLK and S_IFCHR */ | ||
| 60 | #define _XOPEN_SOURCE 1 | ||
| 61 | |||
| 59 | #include <errno.h> | 62 | #include <errno.h> |
| 60 | #include <stdio.h> | 63 | #include <stdio.h> |
| 61 | #include <stdlib.h> | 64 | #include <stdlib.h> |
| @@ -64,6 +67,7 @@ | |||
| 64 | #include "e_os.h" | 67 | #include "e_os.h" |
| 65 | #include <openssl/crypto.h> | 68 | #include <openssl/crypto.h> |
| 66 | #include <openssl/rand.h> | 69 | #include <openssl/rand.h> |
| 70 | #include <openssl/buffer.h> | ||
| 67 | 71 | ||
| 68 | #ifdef OPENSSL_SYS_VMS | 72 | #ifdef OPENSSL_SYS_VMS |
| 69 | #include <unixio.h> | 73 | #include <unixio.h> |
| @@ -106,6 +110,7 @@ int RAND_load_file(const char *file, long bytes) | |||
| 106 | 110 | ||
| 107 | in=fopen(file,"rb"); | 111 | in=fopen(file,"rb"); |
| 108 | if (in == NULL) goto err; | 112 | if (in == NULL) goto err; |
| 113 | #if defined(S_IFBLK) && defined(S_IFCHR) | ||
| 109 | if (sb.st_mode & (S_IFBLK | S_IFCHR)) { | 114 | if (sb.st_mode & (S_IFBLK | S_IFCHR)) { |
| 110 | /* this file is a device. we don't want read an infinite number | 115 | /* this file is a device. we don't want read an infinite number |
| 111 | * of bytes from a random device, nor do we want to use buffered | 116 | * of bytes from a random device, nor do we want to use buffered |
| @@ -114,6 +119,7 @@ int RAND_load_file(const char *file, long bytes) | |||
| 114 | bytes = (bytes == -1) ? 2048 : bytes; /* ok, is 2048 enough? */ | 119 | bytes = (bytes == -1) ? 2048 : bytes; /* ok, is 2048 enough? */ |
| 115 | setvbuf(in, NULL, _IONBF, 0); /* don't do buffered reads */ | 120 | setvbuf(in, NULL, _IONBF, 0); /* don't do buffered reads */ |
| 116 | } | 121 | } |
| 122 | #endif | ||
| 117 | for (;;) | 123 | for (;;) |
| 118 | { | 124 | { |
| 119 | if (bytes > 0) | 125 | if (bytes > 0) |
| @@ -147,6 +153,7 @@ int RAND_write_file(const char *file) | |||
| 147 | 153 | ||
| 148 | i=stat(file,&sb); | 154 | i=stat(file,&sb); |
| 149 | if (i != -1) { | 155 | if (i != -1) { |
| 156 | #if defined(S_IFBLK) && defined(S_IFCHR) | ||
| 150 | if (sb.st_mode & (S_IFBLK | S_IFCHR)) { | 157 | if (sb.st_mode & (S_IFBLK | S_IFCHR)) { |
| 151 | /* this file is a device. we don't write back to it. | 158 | /* this file is a device. we don't write back to it. |
| 152 | * we "succeed" on the assumption this is some sort | 159 | * we "succeed" on the assumption this is some sort |
| @@ -155,6 +162,7 @@ int RAND_write_file(const char *file) | |||
| 155 | */ | 162 | */ |
| 156 | return(1); | 163 | return(1); |
| 157 | } | 164 | } |
| 165 | #endif | ||
| 158 | } | 166 | } |
| 159 | 167 | ||
| 160 | #if defined(O_CREAT) && !defined(OPENSSL_SYS_WIN32) | 168 | #if defined(O_CREAT) && !defined(OPENSSL_SYS_WIN32) |
| @@ -219,13 +227,15 @@ const char *RAND_file_name(char *buf, size_t size) | |||
| 219 | { | 227 | { |
| 220 | char *s=NULL; | 228 | char *s=NULL; |
| 221 | int ok = 0; | 229 | int ok = 0; |
| 230 | #ifdef __OpenBSD__ | ||
| 222 | struct stat sb; | 231 | struct stat sb; |
| 232 | #endif | ||
| 223 | 233 | ||
| 224 | if (issetugid() == 0) | 234 | if (issetugid() == 0) |
| 225 | s=getenv("RANDFILE"); | 235 | s=getenv("RANDFILE"); |
| 226 | if (s != NULL && *s && strlen(s) + 1 < size) | 236 | if (s != NULL && *s && strlen(s) + 1 < size) |
| 227 | { | 237 | { |
| 228 | if (strlcpy(buf,s,size) >= size) | 238 | if (BUF_strlcpy(buf,s,size) >= size) |
| 229 | return NULL; | 239 | return NULL; |
| 230 | } | 240 | } |
| 231 | else | 241 | else |
| @@ -240,11 +250,11 @@ const char *RAND_file_name(char *buf, size_t size) | |||
| 240 | #endif | 250 | #endif |
| 241 | if (s && *s && strlen(s)+strlen(RFILE)+2 < size) | 251 | if (s && *s && strlen(s)+strlen(RFILE)+2 < size) |
| 242 | { | 252 | { |
| 243 | strlcpy(buf,s,size); | 253 | BUF_strlcpy(buf,s,size); |
| 244 | #ifndef OPENSSL_SYS_VMS | 254 | #ifndef OPENSSL_SYS_VMS |
| 245 | strlcat(buf,"/",size); | 255 | BUF_strlcat(buf,"/",size); |
| 246 | #endif | 256 | #endif |
| 247 | strlcat(buf,RFILE,size); | 257 | BUF_strlcat(buf,RFILE,size); |
| 248 | ok = 1; | 258 | ok = 1; |
| 249 | } | 259 | } |
| 250 | else | 260 | else |
| @@ -260,11 +270,11 @@ const char *RAND_file_name(char *buf, size_t size) | |||
| 260 | */ | 270 | */ |
| 261 | 271 | ||
| 262 | if (!ok) | 272 | if (!ok) |
| 263 | if (strlcpy(buf,"/dev/arandom",size) >= size) { | 273 | if (BUF_strlcpy(buf,"/dev/arandom",size) >= size) { |
| 264 | return(NULL); | 274 | return(NULL); |
| 265 | } | 275 | } |
| 266 | if (stat(buf,&sb) == -1) | 276 | if (stat(buf,&sb) == -1) |
| 267 | if (strlcpy(buf,"/dev/arandom",size) >= size) { | 277 | if (BUF_strlcpy(buf,"/dev/arandom",size) >= size) { |
| 268 | return(NULL); | 278 | return(NULL); |
| 269 | } | 279 | } |
| 270 | 280 | ||
