diff options
author | Oren Milman <orenmn@gmail.com> | 2017-09-11 06:28:39 (GMT) |
---|---|---|
committer | Serhiy Storchaka <storchaka@gmail.com> | 2017-09-11 06:28:39 (GMT) |
commit | 252033d50effa08046ac34fcc406bc99796ab88b (patch) | |
tree | da5a9acc3a8a57688769bba6bbaaebce741846a4 /Python/_warnings.c | |
parent | 3866d9bbcf808cea98b3d00007f9f246b83858ce (diff) | |
download | cpython-252033d50effa08046ac34fcc406bc99796ab88b.zip cpython-252033d50effa08046ac34fcc406bc99796ab88b.tar.gz cpython-252033d50effa08046ac34fcc406bc99796ab88b.tar.bz2 |
bpo-31411: Prevent raising a SystemError in case warnings.onceregistry is not a dictionary. (#3485)
Diffstat (limited to 'Python/_warnings.c')
-rw-r--r-- | Python/_warnings.c | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/Python/_warnings.c b/Python/_warnings.c index 5230318..078bdcb 100644 --- a/Python/_warnings.c +++ b/Python/_warnings.c @@ -86,6 +86,12 @@ get_once_registry(void) return NULL; return _PyRuntime.warnings.once_registry; } + if (!PyDict_Check(registry)) { + PyErr_SetString(PyExc_TypeError, + "warnings.onceregistry must be a dict"); + Py_DECREF(registry); + return NULL; + } Py_DECREF(_PyRuntime.warnings.once_registry); _PyRuntime.warnings.once_registry = registry; return registry; @@ -437,7 +443,7 @@ warn_explicit(PyObject *category, PyObject *message, Py_RETURN_NONE; if (registry && !PyDict_Check(registry) && (registry != Py_None)) { - PyErr_SetString(PyExc_TypeError, "'registry' must be a dict"); + PyErr_SetString(PyExc_TypeError, "'registry' must be a dict or None"); return NULL; } |