summaryrefslogtreecommitdiffstats
path: root/Lib/os.py
diff options
context:
space:
mode:
authorGregory P. Smith <greg@mad-scientist.com>2008-09-02 05:36:11 (GMT)
committerGregory P. Smith <greg@mad-scientist.com>2008-09-02 05:36:11 (GMT)
commitd712203d17d406b3ebdb1276e5f1694a2a7db120 (patch)
treea373256f30cd5a98b54a1bc70d57931a47a87d2c /Lib/os.py
parent2bb25cc1e212109dcba04feed4027a2447ec12d1 (diff)
downloadcpython-d712203d17d406b3ebdb1276e5f1694a2a7db120.zip
cpython-d712203d17d406b3ebdb1276e5f1694a2a7db120.tar.gz
cpython-d712203d17d406b3ebdb1276e5f1694a2a7db120.tar.bz2
Issue #3708: os.urandom no longer goes into an infinite loop when passed a
non-integer floating point number.
Diffstat (limited to 'Lib/os.py')
-rw-r--r--Lib/os.py12
1 files changed, 7 insertions, 5 deletions
diff --git a/Lib/os.py b/Lib/os.py
index 715ff20..abbadc4 100644
--- a/Lib/os.py
+++ b/Lib/os.py
@@ -753,8 +753,10 @@ if not _exists("urandom"):
_urandomfd = open("/dev/urandom", O_RDONLY)
except (OSError, IOError):
raise NotImplementedError("/dev/urandom (or equivalent) not found")
- bytes = ""
- while len(bytes) < n:
- bytes += read(_urandomfd, n - len(bytes))
- close(_urandomfd)
- return bytes
+ try:
+ bs = b""
+ while n - len(bs) >= 1:
+ bs += read(_urandomfd, n - len(bs))
+ finally:
+ close(_urandomfd)
+ return bs