changeset: 100945:fb7628e8dfef branch: 3.5 parent: 100942:f8398dba48fb user: Victor Stinner date: Tue Apr 12 22:28:49 2016 +0200 files: Misc/NEWS Python/random.c description: 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. diff -r f8398dba48fb -r fb7628e8dfef Misc/NEWS --- a/Misc/NEWS Tue Apr 12 18:33:41 2016 +0200 +++ b/Misc/NEWS Tue Apr 12 22:28:49 2016 +0200 @@ -102,6 +102,10 @@ Library ------- +- Issue #26735: Fix :func:`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. + - Issue #16329: Add .webm to mimetypes.types_map. Patch by Giampaolo Rodola'. - Issue #13952: Add .csv to mimetypes.types_map. Patch by Geoff Wilson. diff -r f8398dba48fb -r fb7628e8dfef Python/random.c --- a/Python/random.c Tue Apr 12 18:33:41 2016 +0200 +++ b/Python/random.c Tue Apr 12 22:28:49 2016 +0200 @@ -131,16 +131,23 @@ return 0; while (0 < size) { +#ifdef sun + /* Issue #26735: On Solaris, getrandom() is limited to returning up + to 1024 bytes */ + n = Py_MIN(size, 1024); +#else + n = size; +#endif + errno = 0; - #ifdef HAVE_GETRANDOM if (raise) { Py_BEGIN_ALLOW_THREADS - n = getrandom(buffer, size, flags); + n = getrandom(buffer, n, flags); Py_END_ALLOW_THREADS } else { - n = getrandom(buffer, size, flags); + n = getrandom(buffer, n, flags); } #else /* On Linux, use the syscall() function because the GNU libc doesn't @@ -148,11 +155,11 @@ * https://sourceware.org/bugzilla/show_bug.cgi?id=17252 */ if (raise) { Py_BEGIN_ALLOW_THREADS - n = syscall(SYS_getrandom, buffer, size, flags); + n = syscall(SYS_getrandom, buffer, n, flags); Py_END_ALLOW_THREADS } else { - n = syscall(SYS_getrandom, buffer, size, flags); + n = syscall(SYS_getrandom, buffer, n, flags); } #endif