[Python-checkins] cpython (merge 3.3 -> default): (Merge 3.3) Issue #20025: ssl.RAND_bytes() and ssl.RAND_pseudo_bytes() now
victor.stinner
python-checkins at python.org
Thu Dec 19 16:47:52 CET 2013
http://hg.python.org/cpython/rev/c1d2c90ece99
changeset: 88067:c1d2c90ece99
parent: 88064:2b6802d8bee1
parent: 88066:68ec8949dbf1
user: Victor Stinner <victor.stinner at gmail.com>
date: Thu Dec 19 16:47:25 2013 +0100
summary:
(Merge 3.3) Issue #20025: ssl.RAND_bytes() and ssl.RAND_pseudo_bytes() now
raise a ValueError if num is negative (instead of raising a SystemError).
files:
Lib/test/test_ssl.py | 4 ++++
Modules/_ssl.c | 5 +++++
2 files changed, 9 insertions(+), 0 deletions(-)
diff --git a/Lib/test/test_ssl.py b/Lib/test/test_ssl.py
--- a/Lib/test/test_ssl.py
+++ b/Lib/test/test_ssl.py
@@ -150,6 +150,10 @@
else:
self.assertRaises(ssl.SSLError, ssl.RAND_bytes, 16)
+ # negative num is invalid
+ self.assertRaises(ValueError, ssl.RAND_bytes, -5)
+ self.assertRaises(ValueError, ssl.RAND_pseudo_bytes, -5)
+
self.assertRaises(TypeError, ssl.RAND_egd, 1)
self.assertRaises(TypeError, ssl.RAND_egd, 'foo', 1)
ssl.RAND_add("this is a random string", 75.0)
diff --git a/Modules/_ssl.c b/Modules/_ssl.c
--- a/Modules/_ssl.c
+++ b/Modules/_ssl.c
@@ -3244,6 +3244,11 @@
const char *errstr;
PyObject *v;
+ if (len < 0) {
+ PyErr_SetString(PyExc_ValueError, "num must be positive");
+ return NULL;
+ }
+
bytes = PyBytes_FromStringAndSize(NULL, len);
if (bytes == NULL)
return NULL;
--
Repository URL: http://hg.python.org/cpython
More information about the Python-checkins
mailing list