[Python-checkins] cpython (3.3): Issue #20025: ssl.RAND_bytes() and ssl.RAND_pseudo_bytes() now raise a
victor.stinner
python-checkins at python.org
Thu Dec 19 16:47:51 CET 2013
http://hg.python.org/cpython/rev/68ec8949dbf1
changeset: 88066:68ec8949dbf1
branch: 3.3
parent: 88062:11a161cf0e5d
user: Victor Stinner <victor.stinner at gmail.com>
date: Thu Dec 19 16:47:04 2013 +0100
summary:
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
@@ -126,6 +126,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
@@ -2486,6 +2486,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