]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Backport:
authorNeal Norwitz <nnorwitz@gmail.com>
Sun, 29 Jun 2003 14:57:10 +0000 (14:57 +0000)
committerNeal Norwitz <nnorwitz@gmail.com>
Sun, 29 Jun 2003 14:57:10 +0000 (14:57 +0000)
Fix SF #762455, segfault when sys.stdout is changed in getattr

Note:  in 2.2, the problem was an infinite loop (at least for me).

Python/ceval.c

index d764b54d5e125e49059e9b500d1a42ddad13e68f..e8c14f899b7684d948dccf90772ed2d7fd63fe99 100644 (file)
@@ -1365,6 +1365,11 @@ eval_frame(PyFrameObject *f)
                                        err = -1;
                                }
                        }
+                       /* PyFile_SoftSpace() can exececute arbitrary code
+                          if sys.stdout is an instance with a __getattr__.
+                          If __getattr__ raises an exception, w will
+                          be freed, so we need to prevent that temporarily. */
+                       Py_XINCREF(w);
                        if (w != NULL && PyFile_SoftSpace(w, 1))
                                err = PyFile_WriteString(" ", w);
                        if (err == 0)
@@ -1390,6 +1395,7 @@ eval_frame(PyFrameObject *f)
                            }
 #endif
                        }
+                       Py_XDECREF(w);
                        Py_DECREF(v);
                        Py_XDECREF(stream);
                        stream = NULL;