]> git.ipfire.org Git - thirdparty/bird.git/commitdiff
Better initialization of random generator
authorOndrej Zajicek (work) <santiago@crfreenet.org>
Thu, 3 May 2018 15:07:39 +0000 (17:07 +0200)
committerOndrej Zajicek (work) <santiago@crfreenet.org>
Thu, 3 May 2018 15:07:39 +0000 (17:07 +0200)
Use full time precision to initialize random generator. The old
code was prone to initialize it to the same values in specific
circumstances (boot without RTC, multiple VMs starting at once).

sysdep/unix/io.c

index 012deaf0aa7319ef64fc92eb6ca8b4413d52578c..11a0d6f171c6e8aacd6589e7fec61d934bd56fe9 100644 (file)
@@ -2144,7 +2144,9 @@ io_init(void)
   // XXX init_times();
   // XXX update_times();
   boot_time = current_time();
-  srandom((uint) (current_real_time() TO_S));
+
+  u64 now = (u64) current_real_time();
+  srandom((uint) (now ^ (now >> 32)));
 }
 
 static int short_loops = 0;