changeset 735:73b6e5d8801b

Fix segfault when /dev/urandom isn't writable
author Matt Johnston <matt@ucc.asn.au>
date Tue, 02 Apr 2013 18:53:18 +0800
parents 70811267715c
children 0b854ab00333
files random.c
diffstat 1 files changed, 3 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/random.c	Mon Apr 01 22:26:55 2013 +0800
+++ b/random.c	Tue Apr 02 18:53:18 2013 +0800
@@ -157,6 +157,9 @@
 	/* This is opportunistic, don't worry about failure */
 	unsigned char buf[INIT_SEED_SIZE];
 	FILE *f = fopen(DROPBEAR_URANDOM_DEV, "w");
+    if (!f) {
+        return;
+    }
 	genrandom(buf, sizeof(buf));
 	fwrite(buf, sizeof(buf), 1, f);
 	fclose(f);