bpo-18407: win32_urandom() uses PY_DWORD_MAX (GH-10656) · python/cpython@c48ff73 (original) (raw)

Original file line number Diff line number Diff line change
@@ -55,8 +55,6 @@ win32_urandom_init(int raise)
55 55 static int
56 56 win32_urandom(unsigned char *buffer, Py_ssize_t size, int raise)
57 57 {
58 -Py_ssize_t chunk;
59 -
60 58 if (hCryptProv == 0)
61 59 {
62 60 if (win32_urandom_init(raise) == -1) {
@@ -66,8 +64,8 @@ win32_urandom(unsigned char *buffer, Py_ssize_t size, int raise)
66 64
67 65 while (size > 0)
68 66 {
69 -chunk = size > INT_MAX ? INT_MAX : size;
70 -if (!CryptGenRandom(hCryptProv, (DWORD)chunk, buffer))
67 +DWORD chunk = (DWORD)Py_MIN(size, PY_DWORD_MAX);
68 +if (!CryptGenRandom(hCryptProv, chunk, buffer))
71 69 {
72 70 /* CryptGenRandom() failed */
73 71 if (raise) {