diff --git a/random.c b/random.c
index 0378e9a602d7970b04cfc53d72a03fd8234bcd7a..f935e215cc129b639fa65c369388ddfc24abfa93 100644
--- a/random.c
+++ b/random.c
@@ -157,6 +157,9 @@ static void write_urandom()
 	/* 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);