From a1eac7218ba098746f611e6edcc8eb5b72bc89e7 Mon Sep 17 00:00:00 2001 From: Eric Smith Date: Sat, 29 Jan 2011 11:15:35 +0000 Subject: Issue #11302: missing type check on _string.formatter_field_name_split and _string.formatter_parser caused crash. Originial patch by haypo, reviewed by me, okayed by Georg. --- Objects/stringlib/string_format.h | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'Objects/stringlib/string_format.h') diff --git a/Objects/stringlib/string_format.h b/Objects/stringlib/string_format.h index 40535457f38..c1a6d1d5317 100644 --- a/Objects/stringlib/string_format.h +++ b/Objects/stringlib/string_format.h @@ -1192,6 +1192,11 @@ formatter_parser(PyObject *ignored, STRINGLIB_OBJECT *self) { formatteriterobject *it; + if (!PyUnicode_Check(self)) { + PyErr_Format(PyExc_TypeError, "expected str, got %s", Py_TYPE(self)->tp_name); + return NULL; + } + it = PyObject_New(formatteriterobject, &PyFormatterIter_Type); if (it == NULL) return NULL; @@ -1332,6 +1337,11 @@ formatter_field_name_split(PyObject *ignored, STRINGLIB_OBJECT *self) PyObject *first_obj = NULL; PyObject *result = NULL; + if (!PyUnicode_Check(self)) { + PyErr_Format(PyExc_TypeError, "expected str, got %s", Py_TYPE(self)->tp_name); + return NULL; + } + it = PyObject_New(fieldnameiterobject, &PyFieldNameIter_Type); if (it == NULL) return NULL; -- cgit v1.2.3