Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 36e96b8

Browse files
committed
(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).
2 parents c234f18 + 1e81a39 commit 36e96b8

2 files changed

Lines changed: 9 additions & 0 deletions

File tree

Lib/test/test_ssl.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,10 @@ def test_random(self):
150150
else:
151151
self.assertRaises(ssl.SSLError, ssl.RAND_bytes, 16)
152152

153+
# negative num is invalid
154+
self.assertRaises(ValueError, ssl.RAND_bytes, -5)
155+
self.assertRaises(ValueError, ssl.RAND_pseudo_bytes, -5)
156+
153157
self.assertRaises(TypeError, ssl.RAND_egd, 1)
154158
self.assertRaises(TypeError, ssl.RAND_egd, 'foo', 1)
155159
ssl.RAND_add("this is a random string", 75.0)

Modules/_ssl.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3244,6 +3244,11 @@ PySSL_RAND(int len, int pseudo)
32443244
const char *errstr;
32453245
PyObject *v;
32463246

3247+
if (len < 0) {
3248+
PyErr_SetString(PyExc_ValueError, "num must be positive");
3249+
return NULL;
3250+
}
3251+
32473252
bytes = PyBytes_FromStringAndSize(NULL, len);
32483253
if (bytes == NULL)
32493254
return NULL;

0 commit comments

Comments
 (0)