summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2013-12-19 15:47:25 (GMT)
committerVictor Stinner <victor.stinner@gmail.com>2013-12-19 15:47:25 (GMT)
commit36e96b87165c4050eea5aa70d9538d237c874b33 (patch)
tree7b18f824421e63d2a7fae79ff3dedb498b3c1306
parentc234f185cb37e945f29a702ac5f7a149236f8c65 (diff)
parent1e81a399a25edd23d76601c0c421bdad46b5c19c (diff)
downloadcpython-36e96b87165c4050eea5aa70d9538d237c874b33.zip
cpython-36e96b87165c4050eea5aa70d9538d237c874b33.tar.gz
cpython-36e96b87165c4050eea5aa70d9538d237c874b33.tar.bz2
(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).
-rw-r--r--Lib/test/test_ssl.py4
-rw-r--r--Modules/_ssl.c5
2 files changed, 9 insertions, 0 deletions
diff --git a/Lib/test/test_ssl.py b/Lib/test/test_ssl.py
index 0aa6d04..6eb88d7 100644
--- a/Lib/test/test_ssl.py
+++ b/Lib/test/test_ssl.py
@@ -150,6 +150,10 @@ class BasicSocketTests(unittest.TestCase):
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
index 6b0d67a..a370b1b 100644
--- a/Modules/_ssl.c
+++ b/Modules/_ssl.c
@@ -3244,6 +3244,11 @@ PySSL_RAND(int len, int pseudo)
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;