summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/rand/randfile.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libcrypto/rand/randfile.c')
-rw-r--r--src/lib/libcrypto/rand/randfile.c31
1 files changed, 15 insertions, 16 deletions
diff --git a/src/lib/libcrypto/rand/randfile.c b/src/lib/libcrypto/rand/randfile.c
index c6ff27be0e..29718bdb9d 100644
--- a/src/lib/libcrypto/rand/randfile.c
+++ b/src/lib/libcrypto/rand/randfile.c
@@ -61,8 +61,6 @@
61#include <stdlib.h> 61#include <stdlib.h>
62#include <string.h> 62#include <string.h>
63 63
64#include "openssl/e_os.h"
65
66#ifdef VMS 64#ifdef VMS
67#include <unixio.h> 65#include <unixio.h>
68#endif 66#endif
@@ -75,6 +73,7 @@
75# include <sys/stat.h> 73# include <sys/stat.h>
76#endif 74#endif
77 75
76#include <openssl/e_os.h>
78#include <openssl/crypto.h> 77#include <openssl/crypto.h>
79#include <openssl/rand.h> 78#include <openssl/rand.h>
80 79
@@ -139,7 +138,7 @@ err:
139int RAND_write_file(const char *file) 138int RAND_write_file(const char *file)
140 { 139 {
141 unsigned char buf[BUFSIZE]; 140 unsigned char buf[BUFSIZE];
142 int i,ret=0,err=0; 141 int i,ret=0,rand_err=0;
143 FILE *out = NULL; 142 FILE *out = NULL;
144 int n; 143 int n;
145 struct stat sb; 144 struct stat sb;
@@ -156,18 +155,18 @@ int RAND_write_file(const char *file)
156 } 155 }
157 } 156 }
158 157
159#if defined(O_CREAT) && defined(O_EXCL) && !defined(WIN32) 158#if defined(O_CREAT) && !defined(WIN32)
160 /* For some reason Win32 can't write to files created this way */ 159 /* For some reason Win32 can't write to files created this way */
161 160
162 /* chmod(..., 0600) is too late to protect the file, 161 /* chmod(..., 0600) is too late to protect the file,
163 * permissions should be restrictive from the start */ 162 * permissions should be restrictive from the start */
164 int fd = open(file, O_CREAT | O_EXCL, 0600); 163 int fd = open(file, O_CREAT, 0600);
165 if (fd != -1) 164 if (fd != -1)
166 out = fdopen(fd, "wb"); 165 out = fdopen(fd, "wb");
167#endif 166#endif
168 if (out == NULL) 167 if (out == NULL)
169 out = fopen(file,"wb"); 168 out = fopen(file,"wb");
170 if (out == NULL) goto err; 169 if (out == NULL) goto err;
171 170
172#ifndef NO_CHMOD 171#ifndef NO_CHMOD
173 chmod(file,0600); 172 chmod(file,0600);
@@ -178,7 +177,7 @@ int RAND_write_file(const char *file)
178 i=(n > BUFSIZE)?BUFSIZE:n; 177 i=(n > BUFSIZE)?BUFSIZE:n;
179 n-=BUFSIZE; 178 n-=BUFSIZE;
180 if (RAND_bytes(buf,i) <= 0) 179 if (RAND_bytes(buf,i) <= 0)
181 err=1; 180 rand_err=1;
182 i=fwrite(buf,1,i,out); 181 i=fwrite(buf,1,i,out);
183 if (i <= 0) 182 if (i <= 0)
184 { 183 {
@@ -194,7 +193,7 @@ int RAND_write_file(const char *file)
194 { 193 {
195 char *tmpf; 194 char *tmpf;
196 195
197 tmpf = Malloc(strlen(file) + 4); /* to add ";-1" and a nul */ 196 tmpf = OPENSSL_malloc(strlen(file) + 4); /* to add ";-1" and a nul */
198 if (tmpf) 197 if (tmpf)
199 { 198 {
200 strcpy(tmpf, file); 199 strcpy(tmpf, file);
@@ -211,7 +210,7 @@ int RAND_write_file(const char *file)
211 fclose(out); 210 fclose(out);
212 memset(buf,0,BUFSIZE); 211 memset(buf,0,BUFSIZE);
213err: 212err:
214 return(err ? -1 : ret); 213 return (rand_err ? -1 : ret);
215 } 214 }
216 215
217const char *RAND_file_name(char *buf, int size) 216const char *RAND_file_name(char *buf, int size)