summaryrefslogtreecommitdiffstats
path: root/Python
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2016-04-12 20:38:22 (GMT)
committerVictor Stinner <victor.stinner@gmail.com>2016-04-12 20:38:22 (GMT)
commit7258176c68a5061a5d05ee43f11e99fd94e34364 (patch)
tree597ea7abf56a58a178003e6fe7efb8bcccef623c /Python
parent328cb1fed0c91f50f311cdc545fe0e9303d0dae7 (diff)
parent1b80b24007154d1f5764b1c14b95c80289cd3c34 (diff)
downloadcpython-7258176c68a5061a5d05ee43f11e99fd94e34364.zip
cpython-7258176c68a5061a5d05ee43f11e99fd94e34364.tar.gz
cpython-7258176c68a5061a5d05ee43f11e99fd94e34364.tar.bz2
Merge 3.5 (os.urandom)
Diffstat (limited to 'Python')
-rw-r--r--Python/random.c17
1 files changed, 12 insertions, 5 deletions
diff --git a/Python/random.c b/Python/random.c
index 9b42d54..839d7ad 100644
--- a/Python/random.c
+++ b/Python/random.c
@@ -131,16 +131,23 @@ py_getrandom(void *buffer, Py_ssize_t size, int raise)
return 0;
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
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 @@ py_getrandom(void *buffer, Py_ssize_t size, int raise)
* 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