[openssl-dev] [PATCH] rand/randfile: return the home directory if possible

Sebastian Andrzej Siewior openssl-dev at ml.breakpoint.cc
Tue Sep 20 19:31:42 UTC 2016


From: Sebastian Andrzej Siewior <sebastian at breakpoint.cc>

The command
|$ openssl rand -base64 3
|gIX3
|unable to write 'random state'

the last line is an error because `s' is never initialized if RANDFILE
is not set. It never tries to look for $HOME for the normal user. The
manpage says:

|On all systems, if the environment variable RANDFILE is set, its value
|will be used as the seed file name.

not possible, go on

|Otherwise, the file is called ".rnd", found in platform dependent locations:
| On all other systems
| $HOME

Won't work for "normal" user. This was change in commit fc6076ca272f
("rand/randfile.c: make it non-ASCII-savvy."). Was this change on
purpose?

Signed-off-by: Sebastian Andrzej Siewior <sebastian at breakpoint.cc>
---

 crypto/rand/randfile.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/crypto/rand/randfile.c b/crypto/rand/randfile.c
index 7aeb87174370..0574cfcc3860 100644
--- a/crypto/rand/randfile.c
+++ b/crypto/rand/randfile.c
@@ -318,7 +318,8 @@ const char *RAND_file_name(char *buf, size_t size)
 #else
     if (OPENSSL_issetugid() == 0) {
         s = getenv("RANDFILE");
-    } else {
+    }
+    if (!s) {
         use_randfile = 0;
         if (OPENSSL_issetugid() == 0)
             s = getenv("HOME");
-- 
2.9.3



More information about the openssl-dev mailing list