summaryrefslogtreecommitdiffstats
path: root/Python
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@redhat.com>2018-05-15 18:42:12 (GMT)
committerGitHub <noreply@github.com>2018-05-15 18:42:12 (GMT)
commitb056562860c227bad2e0ba7cd3130e115c007768 (patch)
tree52e5caee0ef0339c549b8ac11b8afad64b45aa3e /Python
parent8709b236fc997077d24b4802320db287640f82e2 (diff)
downloadcpython-b056562860c227bad2e0ba7cd3130e115c007768.zip
cpython-b056562860c227bad2e0ba7cd3130e115c007768.tar.gz
cpython-b056562860c227bad2e0ba7cd3130e115c007768.tar.bz2
bpo-33509: Fix _warnings for module_globals=None (#6833)
Don't crash on warnings.warn_explicit() if module_globals is not a dict.
Diffstat (limited to 'Python')
-rw-r--r--Python/_warnings.c9
1 files changed, 8 insertions, 1 deletions
diff --git a/Python/_warnings.c b/Python/_warnings.c
index 0568af4..29e475d 100644
--- a/Python/_warnings.c
+++ b/Python/_warnings.c
@@ -951,7 +951,14 @@ warnings_warn_explicit(PyObject *self, PyObject *args, PyObject *kwds)
&registry, &module_globals, &sourceobj))
return NULL;
- if (module_globals) {
+ if (module_globals && module_globals != Py_None) {
+ if (!PyDict_Check(module_globals)) {
+ PyErr_Format(PyExc_TypeError,
+ "module_globals must be a dict, not '%.200s'",
+ Py_TYPE(module_globals)->tp_name);
+ return NULL;
+ }
+
source_line = get_source_line(module_globals, lineno);
if (source_line == NULL && PyErr_Occurred()) {
return NULL;