From b98a36e8f3006512f0fa4d94309fb9918eb8abdd Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Tue, 14 Jun 2016 16:31:35 +0200 Subject: Fix os.urandom() using getrandom() on Linux 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 | 4 ++++ Python/random.c | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/Misc/NEWS b/Misc/NEWS index e132b96..7940cdc 100644 --- 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. diff --git a/Python/random.c b/Python/random.c index 07dacfe..b961020 100644 --- a/Python/random.c +++ b/Python/random.c @@ -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; -- cgit v0.12