]> granicus.if.org Git - python/commitdiff
sys_pyfile_write() does nothing if file is NULL
authorVictor Stinner <victor.stinner@haypocalc.com>
Tue, 8 Jun 2010 20:46:00 +0000 (20:46 +0000)
committerVictor Stinner <victor.stinner@haypocalc.com>
Tue, 8 Jun 2010 20:46:00 +0000 (20:46 +0000)
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.

Python/sysmodule.c

index f1da9730c4fc5bdcbfc7c0da4a470aa085a5bc06..9ec8ab1489d085c22c01ee5660276daa628c5f9b 100644 (file)
@@ -1839,6 +1839,9 @@ sys_pyfile_write(const char *text, PyObject *file)
     PyObject *unicode = NULL, *writer = NULL, *args = NULL, *result = NULL;
     int err;
 
+    if (file == NULL)
+        return -1;
+
     unicode = PyUnicode_FromString(text);
     if (unicode == NULL)
         goto error;