get_random_data() can return NULL (for instance, if we can't open /dev/random
authorjacob <jacob@cda61777-01e9-0310-a592-d414129be87e>
Tue, 13 Mar 2007 14:43:14 +0000 (14:43 +0000)
committerjacob <jacob@cda61777-01e9-0310-a592-d414129be87e>
Tue, 13 Mar 2007 14:43:14 +0000 (14:43 +0000)
on Unix), yet cmdgen failed to deal with this. Spotted by Darren Tucker.

git-svn-id: svn://svn.tartarus.org/sgt/putty@7396 cda61777-01e9-0310-a592-d414129be87e

cmdgen.c

index d8d5a94..9aa585f 100644 (file)
--- a/cmdgen.c
+++ b/cmdgen.c
@@ -640,6 +640,11 @@ int main(int argc, char **argv)
 
        random_ref();
        entropy = get_random_data(bits / 8);
+       if (!entropy) {
+           fprintf(stderr, "puttygen: failed to collect entropy, "
+                   "could not generate key\n");
+           return 1;
+       }
        random_add_heavynoise(entropy, bits / 8);
        memset(entropy, 0, bits/8);
        sfree(entropy);