]> granicus.if.org Git - python/commitdiff
Bug #1535165: fixed a segfault in input() and raw_input() when
authorGeorg Brandl <georg@python.org>
Sun, 6 Aug 2006 08:23:54 +0000 (08:23 +0000)
committerGeorg Brandl <georg@python.org>
Sun, 6 Aug 2006 08:23:54 +0000 (08:23 +0000)
sys.stdin is closed.

Lib/test/test_builtin.py
Misc/NEWS
Python/bltinmodule.c

index bcb4424d0ecdbfcafd53bdfde07d4081a0914d2b..eca284a4c0345b43d5d26e3ba4cc590728b569e7 100644 (file)
@@ -1432,6 +1432,14 @@ class BuiltinTest(unittest.TestCase):
             self.assertEqual(input('testing\n'), 2)
             self.assertEqual(raw_input(), 'The quick brown fox jumps over the lazy dog.')
             self.assertEqual(raw_input('testing\n'), 'Dear John')
+            
+            # SF 1535165: don't segfault on closed stdin
+            # sys.stdout must be a regular file for triggering
+            sys.stdout = savestdout
+            sys.stdin.close()
+            self.assertRaises(ValueError, input, 'prompt')
+
+            sys.stdout = BitBucket()
             sys.stdin = cStringIO.StringIO("NULL\0")
             self.assertRaises(TypeError, input, 42, 42)
             sys.stdin = cStringIO.StringIO("    'whitespace'")
index f06f98c063fed51df0733a31ee5dfb9cb8fd9134..95b2d4eb3cb4a86bef8e474dcdd56c4ed62c4ab5 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -12,6 +12,9 @@ What's New in Python 2.5 release candidate 1?
 Core and builtins
 -----------------
 
+- Bug #1535165: fixed a segfault in input() and raw_input() when
+  sys.stdin is closed.
+
 - On Windows, the PyErr_Warn function is now exported from
   the Python dll again.
 
index 6fcc05e077803d93b1be3dbde8f1261b5e60a119..58dc7c956b92ef6f419b7d70c98c3b5ec4edd7b2 100644 (file)
@@ -1725,7 +1725,7 @@ builtin_raw_input(PyObject *self, PyObject *args)
                if (PyFile_WriteString(" ", fout) != 0)
                        return NULL;
        }
-       if (PyFile_Check(fin) && PyFile_Check(fout)
+       if (PyFile_AsFile(fin) && PyFile_AsFile(fout)
             && isatty(fileno(PyFile_AsFile(fin)))
             && isatty(fileno(PyFile_AsFile(fout)))) {
                PyObject *po;