summaryrefslogtreecommitdiff
path: root/Python/random.c
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2016-07-17 11:35:35 +0300
committerSerhiy Storchaka <storchaka@gmail.com>2016-07-17 11:35:35 +0300
commit5a515b0afe6a2bc273211ba47fd8fe04c56517c7 (patch)
tree3ad22d25ea8682901b955112ac4531c88e779c41 /Python/random.c
parentddf00b0a227950067b93a1bc828477b59aa4f78c (diff)
parent759f8db1106193b1a15bfd442eccde9522301023 (diff)
downloadcpython-5a515b0afe6a2bc273211ba47fd8fe04c56517c7.tar.gz
Issue #17711: Fixed unpickling by the persistent ID with protocol 0.
Original patch by Alexandre Vassalotti.
Diffstat (limited to 'Python/random.c')
-rw-r--r--Python/random.c15
1 files changed, 9 insertions, 6 deletions
diff --git a/Python/random.c b/Python/random.c
index 3119872abd..c8e844ee67 100644
--- a/Python/random.c
+++ b/Python/random.c
@@ -132,11 +132,14 @@ py_getrandom(void *buffer, Py_ssize_t size, int raise)
* see https://bugs.python.org/issue26839. To avoid this, use the
* GRND_NONBLOCK flag. */
const int flags = GRND_NONBLOCK;
+
+ char *dest;
long n;
if (!getrandom_works)
return 0;
+ dest = buffer;
while (0 < size) {
#ifdef sun
/* Issue #26735: On Solaris, getrandom() is limited to returning up
@@ -150,11 +153,11 @@ py_getrandom(void *buffer, Py_ssize_t size, int raise)
#ifdef HAVE_GETRANDOM
if (raise) {
Py_BEGIN_ALLOW_THREADS
- n = getrandom(buffer, n, flags);
+ n = getrandom(dest, n, flags);
Py_END_ALLOW_THREADS
}
else {
- n = getrandom(buffer, n, flags);
+ n = getrandom(dest, n, flags);
}
#else
/* On Linux, use the syscall() function because the GNU libc doesn't
@@ -162,11 +165,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, n, flags);
+ n = syscall(SYS_getrandom, dest, n, flags);
Py_END_ALLOW_THREADS
}
else {
- n = syscall(SYS_getrandom, buffer, n, flags);
+ n = syscall(SYS_getrandom, dest, n, flags);
}
#endif
@@ -204,7 +207,7 @@ py_getrandom(void *buffer, Py_ssize_t size, int raise)
return -1;
}
- buffer += n;
+ dest += n;
size -= n;
}
return 1;
@@ -404,7 +407,7 @@ _PyRandom_Init(void)
char *env;
unsigned char *secret = (unsigned char *)&_Py_HashSecret.uc;
Py_ssize_t secret_size = sizeof(_Py_HashSecret_t);
- assert(secret_size == sizeof(_Py_HashSecret.uc));
+ Py_BUILD_ASSERT(sizeof(_Py_HashSecret_t) == sizeof(_Py_HashSecret.uc));
if (_Py_HashSecret_Initialized)
return;