summaryrefslogtreecommitdiffstats
path: root/Lib/secrets.py
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2016-12-30 05:54:25 (GMT)
committerRaymond Hettinger <python@rcn.com>2016-12-30 05:54:25 (GMT)
commite9ee207622f0f78e31b8277ccb9eaa895ea3472d (patch)
treeb1f0113b031a3dcc5343a68393337ecd94b58bd8 /Lib/secrets.py
parent9ea82ddad55d38ffad3cff5ce8afadaf0eaa59a3 (diff)
downloadcpython-e9ee207622f0f78e31b8277ccb9eaa895ea3472d.zip
cpython-e9ee207622f0f78e31b8277ccb9eaa895ea3472d.tar.gz
cpython-e9ee207622f0f78e31b8277ccb9eaa895ea3472d.tar.bz2
Issue #29061: secrets.randbelow() would hang with a negative input
Diffstat (limited to 'Lib/secrets.py')
-rw-r--r--Lib/secrets.py2
1 files changed, 2 insertions, 0 deletions
diff --git a/Lib/secrets.py b/Lib/secrets.py
index 27fa450..1304342 100644
--- a/Lib/secrets.py
+++ b/Lib/secrets.py
@@ -26,6 +26,8 @@ choice = _sysrand.choice
def randbelow(exclusive_upper_bound):
"""Return a random int in the range [0, n)."""
+ if exclusive_upper_bound <= 0:
+ raise ValueError("Upper bound must be positive.")
return _sysrand._randbelow(exclusive_upper_bound)
DEFAULT_ENTROPY = 32 # number of bytes to return by default