cpython: fb7628e8dfef (original) (raw)
Mercurial > cpython
changeset 100945:fb7628e8dfef 3.5
Fix os.urandom() on Solaris 11.3 Issue #26735: Fix os.urandom() on Solaris 11.3 and newer when reading more than 1,024 bytes: call getrandom() multiple times with a limit of 1024 bytes per call. [#26735]
Victor Stinner victor.stinner@gmail.com | |
---|---|
date | Tue, 12 Apr 2016 22:28:49 +0200 |
parents | f8398dba48fb |
children | f6a5d26a157d |
files | Misc/NEWS Python/random.c |
diffstat | 2 files changed, 16 insertions(+), 5 deletions(-)[+] [-] Misc/NEWS 4 Python/random.c 17 |
line wrap: on
line diff
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -102,6 +102,10 @@ Core and Builtins
Library
-------
+- Issue #26735: Fix :func:os.urandom
on Solaris 11.3 and newer when reading
- Issue #16329: Add .webm to mimetypes.types_map. Patch by Giampaolo Rodola'.
- Issue #13952: Add .csv to mimetypes.types_map. Patch by Geoff Wilson.
--- a/Python/random.c +++ b/Python/random.c @@ -131,16 +131,23 @@ py_getrandom(void *buffer, Py_ssize_t si return 0; while (0 < size) { +#ifdef sun
/* Issue #26735: On Solaris, getrandom() is limited to returning up[](#l2.8)
to 1024 bytes */[](#l2.9)
n = Py_MIN(size, 1024);[](#l2.10)
n = size;[](#l2.12)
+#endif + errno = 0; - #ifdef HAVE_GETRANDOM if (raise) { Py_BEGIN_ALLOW_THREADS
n = getrandom(buffer, size, flags);[](#l2.20)
n = getrandom(buffer, n, flags);[](#l2.21) Py_END_ALLOW_THREADS[](#l2.22) }[](#l2.23) else {[](#l2.24)
n = getrandom(buffer, size, flags);[](#l2.25)
n = getrandom(buffer, n, flags);[](#l2.26) }[](#l2.27)
#else /* On Linux, use the syscall() function because the GNU libc doesn't @@ -148,11 +155,11 @@ py_getrandom(void *buffer, Py_ssize_t si * https://sourceware.org/bugzilla/show_bug.cgi?id=17252 */ if (raise) { Py_BEGIN_ALLOW_THREADS
n = syscall(SYS_getrandom, buffer, size, flags);[](#l2.34)
n = syscall(SYS_getrandom, buffer, n, flags);[](#l2.35) Py_END_ALLOW_THREADS[](#l2.36) }[](#l2.37) else {[](#l2.38)
n = syscall(SYS_getrandom, buffer, size, flags);[](#l2.39)
n = syscall(SYS_getrandom, buffer, n, flags);[](#l2.40) }[](#l2.41)