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

Skip to content

Commit ecccc4f

Browse files
author
Victor Stinner
committed
sys_pyfile_write() does nothing if file is NULL
mywrite() falls back to the C file object if sys_pyfile_write() returns an error. This patch fixes a segfault is Py_FatalError() is called in an early stage of Python initialization.
1 parent 6491248 commit ecccc4f

1 file changed

Lines changed: 3 additions & 0 deletions

File tree

Python/sysmodule.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1839,6 +1839,9 @@ sys_pyfile_write(const char *text, PyObject *file)
18391839
PyObject *unicode = NULL, *writer = NULL, *args = NULL, *result = NULL;
18401840
int err;
18411841

1842+
if (file == NULL)
1843+
return -1;
1844+
18421845
unicode = PyUnicode_FromString(text);
18431846
if (unicode == NULL)
18441847
goto error;

0 commit comments

Comments
 (0)