Manoj Gupta | 8565770 | 2018-11-05 18:26:27 -0800 | [diff] [blame^] | 1 | Don't use getentropy() on Linux |
| 2 | |
| 3 | Issue #29188: Support glibc 2.24 on Linux: don't use getentropy() function but |
| 4 | read from /dev/urandom to get random bytes, for example in os.urandom(). On |
| 5 | Linux, getentropy() is implemented which getrandom() is blocking mode, whereas |
| 6 | os.urandom() should not block. [#29188] |
| 7 | author Victor Stinner <victor.stinner@gmail.com> |
| 8 | date Mon, 09 Jan 2017 11:10:41 +0100 (22 months ago) |
| 9 | |
| 10 | Note: Patch is modfied from upstream to apply to |
| 11 | python 2.7.10. |
| 12 | |
| 13 | diff --git a/Python/random.c b/Python/random.c |
| 14 | index d94f89a..c33fe07 100644 |
| 15 | --- a/Python/random.c |
| 16 | +++ b/Python/random.c |
| 17 | @@ -333,7 +333,7 @@ _PyOS_URandom(void *buffer, Py_ssize_t size) |
| 18 | |
| 19 | #ifdef MS_WINDOWS |
| 20 | return win32_urandom((unsigned char *)buffer, size, 1); |
| 21 | -#elif HAVE_GETENTROPY |
| 22 | +#elif HAVE_GETENTROPY && !defined(sun) && !defined(linux) |
| 23 | return py_getentropy(buffer, size, 0); |
| 24 | #else |
| 25 | # ifdef __VMS |