Merge 3.5 (os.urandom)

This commit is contained in:
Victor Stinner 2016-04-12 22:38:22 +02:00
commit 7258176c68
4 changed files with 101 additions and 88 deletions

View file

@ -240,6 +240,10 @@ Core and Builtins
Library 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 #26585: Eliminate http.server._quote_html() and use - Issue #26585: Eliminate http.server._quote_html() and use
html.escape(quote=False). Patch by Xiang Zhang. html.escape(quote=False). Patch by Xiang Zhang.

View file

@ -131,16 +131,23 @@ py_getrandom(void *buffer, Py_ssize_t size, int raise)
return 0; return 0;
while (0 < size) { while (0 < size) {
errno = 0; #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 #ifdef HAVE_GETRANDOM
if (raise) { if (raise) {
Py_BEGIN_ALLOW_THREADS Py_BEGIN_ALLOW_THREADS
n = getrandom(buffer, size, flags); n = getrandom(buffer, n, flags);
Py_END_ALLOW_THREADS Py_END_ALLOW_THREADS
} }
else { else {
n = getrandom(buffer, size, flags); n = getrandom(buffer, n, flags);
} }
#else #else
/* On Linux, use the syscall() function because the GNU libc doesn't /* On Linux, use the syscall() function because the GNU libc doesn't
@ -148,11 +155,11 @@ py_getrandom(void *buffer, Py_ssize_t size, int raise)
* https://sourceware.org/bugzilla/show_bug.cgi?id=17252 */ * https://sourceware.org/bugzilla/show_bug.cgi?id=17252 */
if (raise) { if (raise) {
Py_BEGIN_ALLOW_THREADS Py_BEGIN_ALLOW_THREADS
n = syscall(SYS_getrandom, buffer, size, flags); n = syscall(SYS_getrandom, buffer, n, flags);
Py_END_ALLOW_THREADS Py_END_ALLOW_THREADS
} }
else { else {
n = syscall(SYS_getrandom, buffer, size, flags); n = syscall(SYS_getrandom, buffer, n, flags);
} }
#endif #endif

1
configure vendored
View file

@ -16276,6 +16276,7 @@ cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */ /* end confdefs.h. */
#include <unistd.h>
#include <sys/syscall.h> #include <sys/syscall.h>
int main() { int main() {

View file

@ -5204,6 +5204,7 @@ AC_MSG_CHECKING(for the Linux getrandom() syscall)
AC_LINK_IFELSE( AC_LINK_IFELSE(
[ [
AC_LANG_SOURCE([[ AC_LANG_SOURCE([[
#include <unistd.h>
#include <sys/syscall.h> #include <sys/syscall.h>
int main() { int main() {