summaryrefslogtreecommitdiff
path: root/lib/libssl
diff options
context:
space:
mode:
authorBob Beck <beck@cvs.openbsd.org>2001-12-20 18:14:37 +0000
committerBob Beck <beck@cvs.openbsd.org>2001-12-20 18:14:37 +0000
commit6743d0464c802e3119c4632471d95b000cfa0d89 (patch)
treec0b3cdc3b185b1fefa07c7bf9f44686457c02c7a /lib/libssl
parentc96a924651d828720924b81b19eeb6067b04e8df (diff)
fix to match documented behaviour. RAND_file_name must return a pointer to
buf, not something else.
Diffstat (limited to 'lib/libssl')
-rw-r--r--lib/libssl/src/crypto/rand/randfile.c22
1 files changed, 13 insertions, 9 deletions
diff --git a/lib/libssl/src/crypto/rand/randfile.c b/lib/libssl/src/crypto/rand/randfile.c
index 2ffb84c89e2..c4eb79ac5f3 100644
--- a/lib/libssl/src/crypto/rand/randfile.c
+++ b/lib/libssl/src/crypto/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);
}