Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c7cd12d

Browse files
committed
Issue #22181: Fix dev_urandom_noraise(), try calling py_getrandom() before
opening /dev/urandom.
1 parent 66aab0c commit c7cd12d

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

Python/random.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -166,17 +166,17 @@ dev_urandom_noraise(unsigned char *buffer, Py_ssize_t size)
166166

167167
assert (0 < size);
168168

169-
fd = _Py_open_noraise("/dev/urandom", O_RDONLY);
170-
if (fd < 0)
171-
Py_FatalError("Failed to open /dev/urandom");
172-
173169
#ifdef HAVE_GETRANDOM_SYSCALL
174170
if (py_getrandom(buffer, size, 0) == 1)
175171
return;
176172
/* getrandom() is not supported by the running kernel, fall back
177173
* on reading /dev/urandom */
178174
#endif
179175

176+
fd = _Py_open_noraise("/dev/urandom", O_RDONLY);
177+
if (fd < 0)
178+
Py_FatalError("Failed to open /dev/urandom");
179+
180180
while (0 < size)
181181
{
182182
do {

0 commit comments

Comments
 (0)