]> git.pond.sub.org Git - empserver/commitdiff
chance: Avoid abuse of O_NONBLOCK for Windows
authorMarkus Armbruster <armbru@pond.sub.org>
Wed, 27 Jan 2021 07:36:34 +0000 (08:36 +0100)
committerMarkus Armbruster <armbru@pond.sub.org>
Sat, 13 Feb 2021 18:25:18 +0000 (19:25 +0100)
O_NONBLOCK from src/lib/w32/w32misc.h is stricly for use with our
fcntl().  pick_seed() passes it to open(), which is wrong.  With any
luck, open() fails as it should anyway (the files being opened are not
expected to exist under Windows).  Messed up in commit 9102ecce5 "Fix
PRNG seeding to resist guessing", v4.3.31.

Clean up: guard with #ifndef _WIN32.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
src/lib/gen/chance.c

index c415c0854257f294768c236940c77a3c36fd6e9b..35ed982452627138547a0bf70be616a0693d8240 100644 (file)
@@ -27,7 +27,7 @@
  *  chance.c: Roll dice
  *
  *  Known contributors to this file:
- *     Markus Armbruster, 2006-2012
+ *     Markus Armbruster, 2006-2021
  */
 
 #include <config.h>
@@ -140,11 +140,12 @@ djb_hash(unsigned hash, void *buf, size_t sz)
 unsigned
 pick_seed(void)
 {
-    int fd;
     unsigned seed;
     int got_seed = 0;
     struct timeval tv;
     pid_t pid;
+#ifndef _WIN32
+    int fd;
 
     /*
      * Modern systems provide random number devices, but the details
@@ -164,6 +165,7 @@ pick_seed(void)
        got_seed = read(fd, &seed, sizeof(seed)) == sizeof(seed);
        close(fd);
     }
+#endif
 
     if (!got_seed) {
        /* Kernel didn't provide, fall back to hashing time and PID */