From 7e3ba2a699d6a5660fc7bf239b2090d5b2961b8c Mon Sep 17 00:00:00 2001 From: Georg Brandl Date: Sun, 6 Aug 2006 08:23:54 +0000 Subject: Bug #1535165: fixed a segfault in input() and raw_input() when sys.stdin is closed. --- Lib/test/test_builtin.py | 8 ++++++++ Misc/NEWS | 3 +++ Python/bltinmodule.c | 2 +- 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/Lib/test/test_builtin.py b/Lib/test/test_builtin.py index bcb4424..eca284a 100644 --- a/Lib/test/test_builtin.py +++ b/Lib/test/test_builtin.py @@ -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'") diff --git a/Misc/NEWS b/Misc/NEWS index f06f98c..95b2d4e 100644 --- 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. diff --git a/Python/bltinmodule.c b/Python/bltinmodule.c index 6fcc05e..58dc7c9 100644 --- a/Python/bltinmodule.c +++ b/Python/bltinmodule.c @@ -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; -- cgit v0.12