diff options
-rw-r--r-- | Lib/test/test_ssl.py | 4 | ||||
-rw-r--r-- | 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 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; |