summaryrefslogtreecommitdiff
path: root/Python/random.c
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2015-03-19 23:24:45 +0100
committerVictor Stinner <victor.stinner@gmail.com>2015-03-19 23:24:45 +0100
commit0f1b4c6827901688b24a202f9f93c25efd5d145f (patch)
tree4e85c536e0181cc8273dedfbd859c9c1a41adaf5 /Python/random.c
parent00471d560c71a73624b8983caf1707ed1610e84d (diff)
downloadcpython-0f1b4c6827901688b24a202f9f93c25efd5d145f.tar.gz
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 10fc505e0f..c924323fda 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 {