summaryrefslogtreecommitdiffstats
path: root/Modules/_json.c
diff options
context:
space:
mode:
authorEzio Melotti <ezio.melotti@gmail.com>2011-05-10 21:55:35 (GMT)
committerEzio Melotti <ezio.melotti@gmail.com>2011-05-10 21:55:35 (GMT)
commitc1ec7b5d441fb6dfdf9499f8fc88a6d891c500be (patch)
treebd5b7c20366ff95f61de7b0796765ea9fc48a237 /Modules/_json.c
parent47d1d0dc30a81f507fd51cd4c2abfaec735fdf13 (diff)
downloadcpython-c1ec7b5d441fb6dfdf9499f8fc88a6d891c500be.zip
cpython-c1ec7b5d441fb6dfdf9499f8fc88a6d891c500be.tar.gz
cpython-c1ec7b5d441fb6dfdf9499f8fc88a6d891c500be.tar.bz2
#12051: Fix segfault in json.dumps() while encoding highly-nested objects using the C accelerations.
Diffstat (limited to 'Modules/_json.c')
-rw-r--r--Modules/_json.c17
1 files changed, 15 insertions, 2 deletions
diff --git a/Modules/_json.c b/Modules/_json.c
index 4b4ef89..6b321e5 100644
--- a/Modules/_json.c
+++ b/Modules/_json.c
@@ -1999,10 +1999,18 @@ encoder_listencode_obj(PyEncoderObject *s, PyObject *rval, PyObject *obj, Py_ssi
return _steal_list_append(rval, encoded);
}
else if (PyList_Check(obj) || PyTuple_Check(obj)) {
- return encoder_listencode_list(s, rval, obj, indent_level);
+ if (Py_EnterRecursiveCall(" while encoding a JSON object"))
+ return -1;
+ rv = encoder_listencode_list(s, rval, obj, indent_level);
+ Py_LeaveRecursiveCall();
+ return rv;
}
else if (PyDict_Check(obj)) {
- return encoder_listencode_dict(s, rval, obj, indent_level);
+ if (Py_EnterRecursiveCall(" while encoding a JSON object"))
+ return -1;
+ rv = encoder_listencode_dict(s, rval, obj, indent_level);
+ Py_LeaveRecursiveCall();
+ return rv;
}
else {
PyObject *ident = NULL;
@@ -2028,7 +2036,12 @@ encoder_listencode_obj(PyEncoderObject *s, PyObject *rval, PyObject *obj, Py_ssi
Py_XDECREF(ident);
return -1;
}
+
+ if (Py_EnterRecursiveCall(" while encoding a JSON object"))
+ return -1;
rv = encoder_listencode_obj(s, rval, newobj, indent_level);
+ Py_LeaveRecursiveCall();
+
Py_DECREF(newobj);
if (rv) {
Py_XDECREF(ident);