summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorOren Milman <orenmn@gmail.com>2017-09-24 09:07:12 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2017-09-24 09:07:12 (GMT)
commit2b382dd6121bb1e4b75470fb3ef8555665df3eb6 (patch)
tree72d277a9137185ba934c537d22b9907f77a06e9d /Modules
parent039b25d8fd21f8d5d9e3cb536402d952cf068dc1 (diff)
downloadcpython-2b382dd6121bb1e4b75470fb3ef8555665df3eb6.zip
cpython-2b382dd6121bb1e4b75470fb3ef8555665df3eb6.tar.gz
cpython-2b382dd6121bb1e4b75470fb3ef8555665df3eb6.tar.bz2
bpo-31505: Fix an assertion failure in json, in case _json.make_encoder() received a bad encoder() argument. (#3643)
Diffstat (limited to 'Modules')
-rw-r--r--Modules/_json.c16
1 files changed, 13 insertions, 3 deletions
diff --git a/Modules/_json.c b/Modules/_json.c
index 769696d..13218a6 100644
--- a/Modules/_json.c
+++ b/Modules/_json.c
@@ -1429,10 +1429,20 @@ static PyObject *
encoder_encode_string(PyEncoderObject *s, PyObject *obj)
{
/* Return the JSON representation of a string */
- if (s->fast_encode)
+ PyObject *encoded;
+
+ if (s->fast_encode) {
return s->fast_encode(NULL, obj);
- else
- return PyObject_CallFunctionObjArgs(s->encoder, obj, NULL);
+ }
+ encoded = PyObject_CallFunctionObjArgs(s->encoder, obj, NULL);
+ if (encoded != NULL && !PyUnicode_Check(encoded)) {
+ PyErr_Format(PyExc_TypeError,
+ "encoder() must return a string, not %.80s",
+ Py_TYPE(encoded)->tp_name);
+ Py_DECREF(encoded);
+ return NULL;
+ }
+ return encoded;
}
static int