mirror of
https://github.com/python/cpython.git
synced 2025-08-15 06:10:47 +00:00
- Issue #13703: oCERT-2011-003: add -R command-line option and PYTHONHASHSEED
environment variable, to provide an opt-in way to protect against denial of service attacks due to hash collisions within the dict and set types. Patch by David Malcolm, based on work by Victor Stinner.
This commit is contained in:
parent
f5a5beb339
commit
1e13eb084f
27 changed files with 706 additions and 152 deletions
19
Lib/os.py
19
Lib/os.py
|
@ -742,22 +742,3 @@ try:
|
|||
_make_statvfs_result)
|
||||
except NameError: # statvfs_result may not exist
|
||||
pass
|
||||
|
||||
if not _exists("urandom"):
|
||||
def urandom(n):
|
||||
"""urandom(n) -> str
|
||||
|
||||
Return a string of n random bytes suitable for cryptographic use.
|
||||
|
||||
"""
|
||||
try:
|
||||
_urandomfd = open("/dev/urandom", O_RDONLY)
|
||||
except (OSError, IOError):
|
||||
raise NotImplementedError("/dev/urandom (or equivalent) not found")
|
||||
try:
|
||||
bs = b""
|
||||
while n - len(bs) >= 1:
|
||||
bs += read(_urandomfd, n - len(bs))
|
||||
finally:
|
||||
close(_urandomfd)
|
||||
return bs
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue