]> git.ipfire.org Git - thirdparty/hostap.git/commitdiff
os_unix: Seed random() for os_random()
authorJouni Malinen <j@w1.fi>
Fri, 28 Feb 2020 20:54:36 +0000 (22:54 +0200)
committerJouni Malinen <j@w1.fi>
Fri, 28 Feb 2020 20:59:32 +0000 (22:59 +0200)
While the users of os_random() do not really need strong pseudo random
numebrs, there is no significant harm in seeding random() with data from
os_get_random(), i.e., /dev/urandom, to get different sequence of not so
strong pseudo random values from os_random() for each time the process
is started.

Signed-off-by: Jouni Malinen <j@w1.fi>
src/utils/os_unix.c

index dd504f3ab4079d980a0c446bb7fccfa2dd2f7d15..fc1110b3cc121e79f87dcf91cd3a990e1b924ef0 100644 (file)
@@ -337,6 +337,8 @@ char * os_rel2abs_path(const char *rel_path)
 
 int os_program_init(void)
 {
+       unsigned int seed;
+
 #ifdef ANDROID
        /*
         * We ignore errors here since errors are normal if we
@@ -365,6 +367,9 @@ int os_program_init(void)
        capset(&header, &cap);
 #endif /* ANDROID */
 
+       os_get_random((unsigned char *) &seed, sizeof(seed));
+       srandom(seed);
+
        return 0;
 }