summaryrefslogtreecommitdiffstats
path: root/crypto/rand/randfile.c
diff options
context:
space:
mode:
authorUlf Möller <ulf@openssl.org>2000-01-21 01:15:56 +0000
committerUlf Möller <ulf@openssl.org>2000-01-21 01:15:56 +0000
commite7f97e2d22e386df60c8da63277727a931bf22b7 (patch)
tree45c42494189d95fada508ac3ff806dee37c00d22 /crypto/rand/randfile.c
parent731d9c5fb5d0535e3c84866e3c355cbf21a92a67 (diff)
Check RAND_bytes() return value or use RAND_pseudo_bytes().
Diffstat (limited to 'crypto/rand/randfile.c')
-rw-r--r--crypto/rand/randfile.c7
1 files changed, 4 insertions, 3 deletions
diff --git a/crypto/rand/randfile.c b/crypto/rand/randfile.c
index 97c3ece535..f95ecb0e00 100644
--- a/crypto/rand/randfile.c
+++ b/crypto/rand/randfile.c
@@ -118,7 +118,7 @@ err:
int RAND_write_file(const char *file)
{
unsigned char buf[BUFSIZE];
- int i,ret=0;
+ int i,ret=0,err=0;
FILE *out = NULL;
int n;
@@ -156,7 +156,8 @@ int RAND_write_file(const char *file)
{
i=(n > BUFSIZE)?BUFSIZE:n;
n-=BUFSIZE;
- RAND_bytes(buf,i);
+ if (RAND_bytes(buf,i) <= 0)
+ err=1;
i=fwrite(buf,1,i,out);
if (i <= 0)
{
@@ -169,7 +170,7 @@ int RAND_write_file(const char *file)
fclose(out);
memset(buf,0,BUFSIZE);
err:
- return(ret);
+ return(err ? -1 : ret);
}
char *RAND_file_name(char *buf, int size)