Skip to content

Commit 7ff1822

Browse files
committed
Issue python#15340: Fix importing the random module when /dev/urandom cannot be opened.
This was a regression caused by the hash randomization patch.
1 parent 5f38121 commit 7ff1822

2 files changed

Lines changed: 5 additions & 1 deletion

File tree

‎Misc/NEWS‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,9 @@ Core and Builtins
120120
Library
121121
-------
122122

123+
- Issue #15340: Fix importing the random module when /dev/urandom cannot
124+
be opened. This was a regression caused by the hash randomization patch.
125+
123126
- Issue #15841: The readable(), writable() and seekable() methods of BytesIO
124127
and StringIO objects now raise ValueError when the object has been closed.
125128
Patch by Alessandro Moura.

‎Python/random.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,8 @@ dev_urandom_python(char *buffer, Py_ssize_t size)
165165
Py_END_ALLOW_THREADS
166166
if (fd < 0)
167167
{
168-
PyErr_SetFromErrnoWithFilename(PyExc_OSError, "/dev/urandom");
168+
PyErr_SetString(PyExc_NotImplementedError,
169+
"/dev/urandom (or equivalent) not found");
169170
return -1;
170171
}
171172

0 commit comments

Comments
 (0)