From 01bbb0dcf0e21495f00e556f82d4a36076f998b1 Mon Sep 17 00:00:00 2001 From: Bob Beck Date: Thu, 20 Dec 2001 18:14:37 +0000 Subject: fix to match documented behaviour. RAND_file_name must return a pointer to buf, not something else. --- lib/libcrypto/rand/randfile.c | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) (limited to 'lib') diff --git a/lib/libcrypto/rand/randfile.c b/lib/libcrypto/rand/randfile.c index 2ffb84c89e2..c4eb79ac5f3 100644 --- a/lib/libcrypto/rand/randfile.c +++ b/lib/libcrypto/rand/randfile.c @@ -219,7 +219,7 @@ err: const char *RAND_file_name(char *buf, size_t size) { char *s = NULL; - char *ret=NULL; + int ok = 0; struct stat sb; if (issetugid() == 0) @@ -227,7 +227,7 @@ const char *RAND_file_name(char *buf, size_t size) if (s != NULL && *s && strlen(s) + 1 < size) { strlcpy(buf,s,size); - ret=buf; + ok = 1; } else { @@ -246,7 +246,7 @@ const char *RAND_file_name(char *buf, size_t size) strcat(buf,"/"); #endif strlcat(buf,RFILE,size); - ret=buf; + ok = 1; } else buf[0] = '\0'; /* no file name */ @@ -255,17 +255,21 @@ const char *RAND_file_name(char *buf, size_t size) #ifdef DEVRANDOM /* given that all random loads just fail if the file can't be * seen on a stat, we stat the file we're returning, if it - * fails, use DEVRANDOM instead. the allows the user to + * fails, use DEVRANDOM instead. this allows the user to * use their own source for good random data, but defaults * to something hopefully decent if that isn't available. */ - if (ret == NULL) - ret = DEVRANDOM; + if (!ok) + if (strlcpy(buf,DEVRANDOM,size) >= size) { + return(NULL); + } + if (stat(buf,&sb) == -1) + if (strlcpy(buf,DEVRANDOM,size) >= size) { + return(NULL); + } - if (stat(ret,&sb) == -1) - ret = DEVRANDOM; #endif - return(ret); + return(buf); } -- cgit v1.2.3