Skip to content

Commit b98a36e

Browse files
committed
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.
1 parent fd7f19e commit b98a36e

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

Misc/NEWS

+4
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ Core and Builtins
1313
Library
1414
-------
1515

16+
- Issue #27278: Fix os.urandom() implementation using getrandom() on Linux.
17+
Truncate size to INT_MAX and loop until we collected enough random bytes,
18+
instead of casting a directly Py_ssize_t to int.
19+
1620
- Issue #26386: Fixed ttk.TreeView selection operations with item id's
1721
containing spaces.
1822

Python/random.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ py_getrandom(void *buffer, Py_ssize_t size, int raise)
143143
to 1024 bytes */
144144
n = Py_MIN(size, 1024);
145145
#else
146-
n = size;
146+
n = Py_MIN(size, INT_MAX);
147147
#endif
148148

149149
errno = 0;

0 commit comments

Comments
 (0)