summaryrefslogtreecommitdiff
path: root/lib
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
commit01bbb0dcf0e21495f00e556f82d4a36076f998b1 (patch)
tree020354b0f9ad1930e81d49df10037623283bd91d /lib
parented3602b3306e104c81c8bdc91033cc137c4deb6a (diff)
fix to match documented behaviour. RAND_file_name must return a pointer to
buf, not something else.
Diffstat (limited to 'lib')
-rw-r--r--lib/libcrypto/rand/randfile.c22
1 files changed, 13 insertions, 9 deletions
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);
}