diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2015-09-07 22:37:02 +0300 |
---|---|---|
committer | Serhiy Storchaka <storchaka@gmail.com> | 2015-09-07 22:37:02 +0300 |
commit | abd776743da4e59bc01ed08dec003a9ed068bbb6 (patch) | |
tree | 8fa03eb188836bc0f7a864366609086642bc9acd /Modules | |
parent | 572a08d2404e2b28a7ce2d1b054342d8872c6d4f (diff) | |
download | cpython-abd776743da4e59bc01ed08dec003a9ed068bbb6.tar.gz |
Issue #25019: Fixed a crash caused by setting non-string key of expat parser.
Added additional tests for expat parser attributes.
Based on patch by John Leitch.
Diffstat (limited to 'Modules')
-rw-r--r-- | Modules/pyexpat.c | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/Modules/pyexpat.c b/Modules/pyexpat.c index 19be0c7cc5..c4fdaafb86 100644 --- a/Modules/pyexpat.c +++ b/Modules/pyexpat.c @@ -1341,11 +1341,16 @@ static int xmlparse_setattro(xmlparseobject *self, PyObject *name, PyObject *v) { /* Set attribute 'name' to value 'v'. v==NULL means delete */ + if (!PyUnicode_Check(name)) { + PyErr_Format(PyExc_TypeError, + "attribute name must be string, not '%.200s'", + name->ob_type->tp_name); + return -1; + } if (v == NULL) { PyErr_SetString(PyExc_RuntimeError, "Cannot delete attribute"); return -1; } - assert(PyUnicode_Check(name)); if (PyUnicode_CompareWithASCIIString(name, "buffer_text") == 0) { int b = PyObject_IsTrue(v); if (b < 0) |