summaryrefslogtreecommitdiffstats
path: root/Python/random.c
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2015-03-19 22:24:45 (GMT)
committerVictor Stinner <victor.stinner@gmail.com>2015-03-19 22:24:45 (GMT)
commitc7cd12da6062e19625cfef38aa25ed58a6109fa1 (patch)
tree53be9c5c6c3980b0d13482b115c9b3ae0d4ab1d0 /Python/random.c
parent66aab0c4b5b6b328aebc115f96275e7dcd114f8b (diff)
downloadcpython-c7cd12da6062e19625cfef38aa25ed58a6109fa1.zip
cpython-c7cd12da6062e19625cfef38aa25ed58a6109fa1.tar.gz
cpython-c7cd12da6062e19625cfef38aa25ed58a6109fa1.tar.bz2
Issue #22181: Fix dev_urandom_noraise(), try calling py_getrandom() before
opening /dev/urandom.
Diffstat (limited to 'Python/random.c')
-rw-r--r--Python/random.c8
1 files changed, 4 insertions, 4 deletions
diff --git a/Python/random.c b/Python/random.c
index 10fc505..c924323 100644
--- a/Python/random.c
+++ b/Python/random.c
@@ -166,10 +166,6 @@ dev_urandom_noraise(unsigned char *buffer, Py_ssize_t size)
assert (0 < size);
- fd = _Py_open_noraise("/dev/urandom", O_RDONLY);
- if (fd < 0)
- Py_FatalError("Failed to open /dev/urandom");
-
#ifdef HAVE_GETRANDOM_SYSCALL
if (py_getrandom(buffer, size, 0) == 1)
return;
@@ -177,6 +173,10 @@ dev_urandom_noraise(unsigned char *buffer, Py_ssize_t size)
* on reading /dev/urandom */
#endif
+ fd = _Py_open_noraise("/dev/urandom", O_RDONLY);
+ if (fd < 0)
+ Py_FatalError("Failed to open /dev/urandom");
+
while (0 < size)
{
do {