cpython: 0509844f38df (original) (raw)
Mercurial > cpython
changeset 105894:0509844f38df 3.6
Issue #29061: secrets.randbelow() would hang with a negative input [#29061]
Raymond Hettinger python@rcn.com | |
---|---|
date | Thu, 29 Dec 2016 22:54:25 -0700 |
parents | b09d0a2587da |
children | 96b7b865c100 1003eabb2705 |
files | Lib/secrets.py Lib/test/test_secrets.py Misc/ACKS Misc/NEWS |
diffstat | 4 files changed, 7 insertions(+), 0 deletions(-)[+] [-] Lib/secrets.py 2 Lib/test/test_secrets.py 1 Misc/ACKS 1 Misc/NEWS 3 |
line wrap: on
line diff
--- 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:
return _sysrand._randbelow(exclusive_upper_bound) DEFAULT_ENTROPY = 32 # number of bytes to return by defaultraise ValueError("Upper bound must be positive.")[](#l1.8)
--- a/Lib/test/test_secrets.py +++ b/Lib/test/test_secrets.py @@ -70,6 +70,7 @@ class Random_Tests(unittest.TestCase): for i in range(2, 10): self.assertIn(secrets.randbelow(i), range(i)) self.assertRaises(ValueError, secrets.randbelow, 0)
self.assertRaises(ValueError, secrets.randbelow, -1)[](#l2.7)
class Token_Tests(unittest.TestCase):
--- a/Misc/ACKS +++ b/Misc/ACKS @@ -369,6 +369,7 @@ Daniel Dittmar Josip Djolonga Walter Dörwald Jaromir Dolecek +Brendan Donegan Ismail Donmez Robert Donohue Marcos Donolo