Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c5131bc

Browse files
committed
Fix SF #762455, segfault when sys.stdout is changed in getattr
Will backport.
1 parent 478c105 commit c5131bc

1 file changed

Lines changed: 6 additions & 0 deletions

File tree

Python/ceval.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1501,6 +1501,11 @@ eval_frame(PyFrameObject *f)
15011501
err = -1;
15021502
}
15031503
}
1504+
/* PyFile_SoftSpace() can exececute arbitrary code
1505+
if sys.stdout is an instance with a __getattr__.
1506+
If __getattr__ raises an exception, w will
1507+
be freed, so we need to prevent that temporarily. */
1508+
Py_XINCREF(w);
15041509
if (w != NULL && PyFile_SoftSpace(w, 0))
15051510
err = PyFile_WriteString(" ", w);
15061511
if (err == 0)
@@ -1528,6 +1533,7 @@ eval_frame(PyFrameObject *f)
15281533
else
15291534
PyFile_SoftSpace(w, 1);
15301535
}
1536+
Py_XDECREF(w);
15311537
Py_DECREF(v);
15321538
Py_XDECREF(stream);
15331539
stream = NULL;

0 commit comments

Comments
 (0)