summaryrefslogtreecommitdiffstats
path: root/Objects/object.c
diff options
context:
space:
mode:
authorNeal Norwitz <nnorwitz@gmail.com>2003-01-13 20:13:12 (GMT)
committerNeal Norwitz <nnorwitz@gmail.com>2003-01-13 20:13:12 (GMT)
commit1a9975014f7ddc583a2428fe47d0e17261f98b46 (patch)
treefebd9464101af88429c179aac60f378a6ee680dc /Objects/object.c
parenta974b3939f8f6239018fd0de44530244812191da (diff)
downloadcpython-1a9975014f7ddc583a2428fe47d0e17261f98b46.zip
cpython-1a9975014f7ddc583a2428fe47d0e17261f98b46.tar.gz
cpython-1a9975014f7ddc583a2428fe47d0e17261f98b46.tar.bz2
Fix SF bug #667147, Segmentation fault printing str subclass
Fix infinite recursion which occurred when printing an object whose __str__() returned self. Will backport
Diffstat (limited to 'Objects/object.c')
-rw-r--r--Objects/object.c19
1 files changed, 16 insertions, 3 deletions
diff --git a/Objects/object.c b/Objects/object.c
index 3328643..e3234de 100644
--- a/Objects/object.c
+++ b/Objects/object.c
@@ -158,10 +158,15 @@ _PyObject_Del(PyObject *op)
PyObject_FREE(op);
}
-int
-PyObject_Print(PyObject *op, FILE *fp, int flags)
+/* Implementation of PyObject_Print with recursion checking */
+static int
+internal_print(PyObject *op, FILE *fp, int flags, int nesting)
{
int ret = 0;
+ if (nesting > 10) {
+ PyErr_SetString(PyExc_RuntimeError, "print recursion");
+ return -1;
+ }
if (PyErr_CheckSignals())
return -1;
#ifdef USE_STACKCHECK
@@ -187,7 +192,8 @@ PyObject_Print(PyObject *op, FILE *fp, int flags)
if (s == NULL)
ret = -1;
else {
- ret = PyObject_Print(s, fp, Py_PRINT_RAW);
+ ret = internal_print(s, fp, Py_PRINT_RAW,
+ nesting+1);
}
Py_XDECREF(s);
}
@@ -204,6 +210,13 @@ PyObject_Print(PyObject *op, FILE *fp, int flags)
return ret;
}
+int
+PyObject_Print(PyObject *op, FILE *fp, int flags)
+{
+ return internal_print(op, fp, flags, 0);
+}
+
+
/* For debugging convenience. See Misc/gdbinit for some useful gdb hooks */
void _PyObject_Dump(PyObject* op)
{