[Python-checkins] bpo-18407: win32_urandom() uses PY_DWORD_MAX (GH-10656)
Victor Stinner
webhook-mailer at python.org
Thu Nov 22 08:43:14 EST 2018
https://github.com/python/cpython/commit/c48ff73dd60bec5dcbe64bedeff91e6db26d98bc
commit: c48ff73dd60bec5dcbe64bedeff91e6db26d98bc
branch: master
author: Victor Stinner <vstinner at redhat.com>
committer: GitHub <noreply at github.com>
date: 2018-11-22T14:43:07+01:00
summary:
bpo-18407: win32_urandom() uses PY_DWORD_MAX (GH-10656)
CryptGenRandom() maximum size is PY_DWORD_MAX, not INT_MAX.
Use DWORD type for the 'chunk' variable
Co-Authored-By: Jeremy Kloth <jeremy.kloth at gmail.com>
files:
M Python/bootstrap_hash.c
diff --git a/Python/bootstrap_hash.c b/Python/bootstrap_hash.c
index 793c646f12ba..eb848c8ff6e3 100644
--- a/Python/bootstrap_hash.c
+++ b/Python/bootstrap_hash.c
@@ -55,8 +55,6 @@ win32_urandom_init(int raise)
static int
win32_urandom(unsigned char *buffer, Py_ssize_t size, int raise)
{
- Py_ssize_t chunk;
-
if (hCryptProv == 0)
{
if (win32_urandom_init(raise) == -1) {
@@ -66,8 +64,8 @@ win32_urandom(unsigned char *buffer, Py_ssize_t size, int raise)
while (size > 0)
{
- chunk = size > INT_MAX ? INT_MAX : size;
- if (!CryptGenRandom(hCryptProv, (DWORD)chunk, buffer))
+ DWORD chunk = (DWORD)Py_MIN(size, PY_DWORD_MAX);
+ if (!CryptGenRandom(hCryptProv, chunk, buffer))
{
/* CryptGenRandom() failed */
if (raise) {
More information about the Python-checkins
mailing list