]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Fix os.urandom() using getrandom() on Linux
authorVictor Stinner <victor.stinner@gmail.com>
Tue, 14 Jun 2016 14:31:35 +0000 (16:31 +0200)
committerVictor Stinner <victor.stinner@gmail.com>
Tue, 14 Jun 2016 14:31:35 +0000 (16:31 +0200)
Issue #27278: Fix os.urandom() implementation using getrandom() on Linux.
Truncate size to INT_MAX and loop until we collected enough random bytes,
instead of casting a directly Py_ssize_t to int.

Misc/NEWS
Python/random.c

index e132b968ca3c263b9cdcc7825ba26f39bda55616..7940cdcb6b82393d2c997b22a8123bcad21e0cb1 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -13,6 +13,10 @@ Core and Builtins
 Library
 -------
 
+- Issue #27278: Fix os.urandom() implementation using getrandom() on Linux.
+  Truncate size to INT_MAX and loop until we collected enough random bytes,
+  instead of casting a directly Py_ssize_t to int.
+
 - Issue #26386: Fixed ttk.TreeView selection operations with item id's
   containing spaces.
 
index 07dacfe188e8fb433c30bff70083f30907c88b85..b9610208f6691a2dd9b4179ddb242334871b7bbd 100644 (file)
@@ -143,7 +143,7 @@ py_getrandom(void *buffer, Py_ssize_t size, int raise)
            to 1024 bytes */
         n = Py_MIN(size, 1024);
 #else
-        n = size;
+        n = Py_MIN(size, INT_MAX);
 #endif
 
         errno = 0;