From 004547f97067be2e23ae770f300c0c0d1db1ba27 Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Mon, 11 Sep 2017 10:01:31 +0300 Subject: [2.7] bpo-31411: Prevent raising a SystemError in case warnings.onceregistry is not a dictionary. (GH-3485). (#3493) (cherry picked from commit 252033d50effa08046ac34fcc406bc99796ab88b) --- Python/_warnings.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'Python') diff --git a/Python/_warnings.c b/Python/_warnings.c index 8e8c0cceb3..dd168f9259 100644 --- a/Python/_warnings.c +++ b/Python/_warnings.c @@ -72,6 +72,12 @@ get_once_registry(void) return NULL; return _once_registry; } + if (!PyDict_Check(registry)) { + PyErr_SetString(PyExc_TypeError, + "warnings.onceregistry must be a dict"); + Py_DECREF(registry); + return NULL; + } Py_DECREF(_once_registry); _once_registry = registry; return registry; @@ -296,7 +302,7 @@ warn_explicit(PyObject *category, PyObject *message, int rc; 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; } -- cgit v1.2.1