]> granicus.if.org Git - python/commitdiff
Fix SF #762455, segfault when sys.stdout is changed in getattr
authorNeal Norwitz <nnorwitz@gmail.com>
Sun, 29 Jun 2003 14:48:32 +0000 (14:48 +0000)
committerNeal Norwitz <nnorwitz@gmail.com>
Sun, 29 Jun 2003 14:48:32 +0000 (14:48 +0000)
Will backport.

Python/ceval.c

index 07862d0efed57c592fa1b3c063e98db363abb70b..035520a593b5b14a6a9872ff2946cbb2a5276b60 100644 (file)
@@ -1501,6 +1501,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, 0))
                                err = PyFile_WriteString(" ", w);
                        if (err == 0)
@@ -1528,6 +1533,7 @@ eval_frame(PyFrameObject *f)
                            else
                                PyFile_SoftSpace(w, 1);
                        }
+                       Py_XDECREF(w);
                        Py_DECREF(v);
                        Py_XDECREF(stream);
                        stream = NULL;