From 26d755bc9a2f4ed57aa8a678c7babed52e01dae9 Mon Sep 17 00:00:00 2001 From: simon Date: Tue, 13 Jan 2009 18:18:35 +0000 Subject: [PATCH] Check the two popen() calls in noise_get_heavy for NULL. git-svn-id: svn://svn.tartarus.org/sgt/putty@8411 cda61777-01e9-0310-a592-d414129be87e --- unix/uxnoise.c | 32 +++++++++++++++++++++++++------- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/unix/uxnoise.c b/unix/uxnoise.c index b563f7cb..7ebb9a58 100644 --- a/unix/uxnoise.c +++ b/unix/uxnoise.c @@ -4,6 +4,9 @@ */ #include +#include +#include + #include #include #include @@ -47,19 +50,34 @@ void noise_get_heavy(void (*func) (void *, int)) char buf[512]; FILE *fp; int ret; + int got_dev_urandom = 0; - if (read_dev_urandom(buf, 32)) + if (read_dev_urandom(buf, 32)) { + got_dev_urandom = 1; func(buf, 32); + } fp = popen("ps -axu 2>/dev/null", "r"); - while ( (ret = fread(buf, 1, sizeof(buf), fp)) > 0) - func(buf, ret); - pclose(fp); + if (fp) { + while ( (ret = fread(buf, 1, sizeof(buf), fp)) > 0) + func(buf, ret); + pclose(fp); + } else if (!got_dev_urandom) { + fprintf(stderr, "popen: %s\n" + "Unable to access fallback entropy source\n", strerror(errno)); + exit(1); + } fp = popen("ls -al /tmp 2>/dev/null", "r"); - while ( (ret = fread(buf, 1, sizeof(buf), fp)) > 0) - func(buf, ret); - pclose(fp); + if (fp) { + while ( (ret = fread(buf, 1, sizeof(buf), fp)) > 0) + func(buf, ret); + pclose(fp); + } else if (!got_dev_urandom) { + fprintf(stderr, "popen: %s\n" + "Unable to access fallback entropy source\n", strerror(errno)); + exit(1); + } read_random_seed(func); random_save_seed(); -- 2.11.0