]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Bug #1535165: fixed a segfault in input() and raw_input() when
authorGeorg Brandl <georg@python.org>
Sun, 6 Aug 2006 08:23:59 +0000 (08:23 +0000)
committerGeorg Brandl <georg@python.org>
Sun, 6 Aug 2006 08:23:59 +0000 (08:23 +0000)
sys.stdin is closed.
 (backport from rev. 51129)

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

index f023b117dc8e23bcc9c64b587b8930470a3adf0c..2d044dc437b9df616ce4049ca6f329e700f7e27d 100644 (file)
@@ -1039,6 +1039,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 427e6fe21ac5844c25f0e83e73c73f2a7120acb9..c15925720c5e0ca95f1f490a49da695cf1c1c59a 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -12,6 +12,9 @@ What's New in Python 2.4.4c1?
 Core and builtins
 -----------------
 
+- Bug #1535165: fixed a segfault in input() and raw_input() when
+  sys.stdin is closed.
+
 - Bug #1524310: Properly report errors from FindNextFile in os.listdir.
 
 - Bug #927248: Recursive method-wrapper objects can now safely
index 052ff3c5ed179e65a228f1763fee16626324fd32..6d30391712c6bb3a7b645c47936dc36d6d332cc7 100644 (file)
@@ -1609,7 +1609,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;