summaryrefslogtreecommitdiffstats
path: root/Python/_warnings.c
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2017-09-11 07:01:31 (GMT)
committerGitHub <noreply@github.com>2017-09-11 07:01:31 (GMT)
commit004547f97067be2e23ae770f300c0c0d1db1ba27 (patch)
treef61e4c139de7fe44d7458193edb08c93ac2c99f6 /Python/_warnings.c
parent6ed7aff8948e50708f048f3f7fd41809259d1777 (diff)
downloadcpython-004547f97067be2e23ae770f300c0c0d1db1ba27.zip
cpython-004547f97067be2e23ae770f300c0c0d1db1ba27.tar.gz
cpython-004547f97067be2e23ae770f300c0c0d1db1ba27.tar.bz2
[2.7] bpo-31411: Prevent raising a SystemError in case warnings.onceregistry is not a dictionary. (GH-3485). (#3493)
(cherry picked from commit 252033d50effa08046ac34fcc406bc99796ab88b)
Diffstat (limited to 'Python/_warnings.c')
-rw-r--r--Python/_warnings.c8
1 files changed, 7 insertions, 1 deletions
diff --git a/Python/_warnings.c b/Python/_warnings.c
index 8e8c0cc..dd168f9 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;
}