summaryrefslogtreecommitdiffstats
path: root/Python/random.c
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2017-01-09 10:10:41 (GMT)
committerVictor Stinner <victor.stinner@gmail.com>2017-01-09 10:10:41 (GMT)
commit01bdbad3e951014c58581635b94b22868537901c (patch)
tree7aaccd80fef5b218e8b21b95b64aea6b3e5b98d5 /Python/random.c
parent98b1c82675a419ddfe9f4673fc4a88feaf8363c9 (diff)
downloadcpython-01bdbad3e951014c58581635b94b22868537901c.zip
cpython-01bdbad3e951014c58581635b94b22868537901c.tar.gz
cpython-01bdbad3e951014c58581635b94b22868537901c.tar.bz2
Don't use getentropy() on Linux
Issue #29188: Support glibc 2.24 on Linux: don't use getentropy() function but read from /dev/urandom to get random bytes, for example in os.urandom(). On Linux, getentropy() is implemented which getrandom() is blocking mode, whereas os.urandom() should not block.
Diffstat (limited to 'Python/random.c')
-rw-r--r--Python/random.c11
1 files changed, 9 insertions, 2 deletions
diff --git a/Python/random.c b/Python/random.c
index 57c41ff..000cb36 100644
--- a/Python/random.c
+++ b/Python/random.c
@@ -97,8 +97,15 @@ win32_urandom(unsigned char *buffer, Py_ssize_t size, int raise)
}
/* Issue #25003: Don't use getentropy() on Solaris (available since
- * Solaris 11.3), it is blocking whereas os.urandom() should not block. */
-#elif defined(HAVE_GETENTROPY) && !defined(sun)
+ Solaris 11.3), it is blocking whereas os.urandom() should not block.
+
+ Issue #29188: Don't use getentropy() on Linux since the glibc 2.24
+ implements it with the getrandom() syscall which can fail with ENOSYS,
+ and this error is not supported in py_getentropy() and getrandom() is called
+ with flags=0 which blocks until system urandom is initialized, which is not
+ the desired behaviour to seed the Python hash secret nor for os.urandom():
+ see the PEP 524 which was only implemented in Python 3.6. */
+#elif defined(HAVE_GETENTROPY) && !defined(sun) && !defined(linux)
#define PY_GETENTROPY 1
/* Fill buffer with size pseudo-random bytes generated by getentropy().