Skip to content

Commit 7258176

Browse files
committed
Merge 3.5 (os.urandom)
2 parents 328cb1f + 1b80b24 commit 7258176

File tree

4 files changed

+101
-88
lines changed

4 files changed

+101
-88
lines changed

Misc/NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,10 @@ Core and Builtins
240240
Library
241241
-------
242242

243+
- Issue #26735: Fix :func:`os.urandom` on Solaris 11.3 and newer when reading
244+
more than 1,024 bytes: call ``getrandom()`` multiple times with a limit of
245+
1024 bytes per call.
246+
243247
- Issue #26585: Eliminate http.server._quote_html() and use
244248
html.escape(quote=False). Patch by Xiang Zhang.
245249

Python/random.c

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -131,28 +131,35 @@ py_getrandom(void *buffer, Py_ssize_t size, int raise)
131131
return 0;
132132

133133
while (0 < size) {
134-
errno = 0;
134+
#ifdef sun
135+
/* Issue #26735: On Solaris, getrandom() is limited to returning up
136+
to 1024 bytes */
137+
n = Py_MIN(size, 1024);
138+
#else
139+
n = size;
140+
#endif
135141

142+
errno = 0;
136143
#ifdef HAVE_GETRANDOM
137144
if (raise) {
138145
Py_BEGIN_ALLOW_THREADS
139-
n = getrandom(buffer, size, flags);
146+
n = getrandom(buffer, n, flags);
140147
Py_END_ALLOW_THREADS
141148
}
142149
else {
143-
n = getrandom(buffer, size, flags);
150+
n = getrandom(buffer, n, flags);
144151
}
145152
#else
146153
/* On Linux, use the syscall() function because the GNU libc doesn't
147154
* expose the Linux getrandom() syscall yet. See:
148155
* https://sourceware.org/bugzilla/show_bug.cgi?id=17252 */
149156
if (raise) {
150157
Py_BEGIN_ALLOW_THREADS
151-
n = syscall(SYS_getrandom, buffer, size, flags);
158+
n = syscall(SYS_getrandom, buffer, n, flags);
152159
Py_END_ALLOW_THREADS
153160
}
154161
else {
155-
n = syscall(SYS_getrandom, buffer, size, flags);
162+
n = syscall(SYS_getrandom, buffer, n, flags);
156163
}
157164
#endif
158165

configure

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16276,6 +16276,7 @@ cat confdefs.h - <<_ACEOF >conftest.$ac_ext
1627616276
/* end confdefs.h. */
1627716277
1627816278
16279+
#include <unistd.h>
1627916280
#include <sys/syscall.h>
1628016281
1628116282
int main() {

0 commit comments

Comments
 (0)