This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Title: segfault if redirecting directory
Type: Stage:
Components: Interpreter Core Versions: Python 2.4
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: nnorwitz Nosy List: inyeol, mbp, ncoghlan, nnorwitz
Priority: high Keywords:

Created on 2004-01-31 00:42 by inyeol, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (7)
msg19865 - (view) Author: Inyeol Lee (inyeol) Date: 2004-01-31 00:42
If redirecting directory, python crashes.

$ uname -a
SunOS xxxxx 5.8 Generic_108528-18 sun4u sparc
$ python
Python 2.3.2 (#1, Oct  9 2003, 18:59:04) 
[GCC 2.95.3 20010315 (release)] on sunos5
Type "help", "copyright", "credits" or "license" for
more information.
>>> ^D
$ mkdir foo
$ ls -F
$ python < foo
Segmentation Fault

-Inyeol Lee
msg19866 - (view) Author: Inyeol Lee (inyeol) Date: 2004-11-04 19:10
Logged In: YES 

I did some more test among different versions;
2.4b1/Solaris - segfault
2.3.3/Linux - segfault
2.3.2/Solaris - segfault
2.1.1/Linux - OK
1.5.2/Linux - OK
msg19867 - (view) Author: Nick Coghlan (ncoghlan) * (Python committer) Date: 2004-11-22 12:24
Logged In: YES 

Win XP SP 1 - 

C:\Python24>python < Lib
"Access is Denied"
msg19868 - (view) Author: Nick Coghlan (ncoghlan) * (Python committer) Date: 2004-11-22 12:32
Logged In: YES 

Python's C main function assumes stdin, stdout and stderr
are all valid FILE pointers.

A little experimentation on a Linux box should establish
what glibc is providing when the input pipe isn't a proper
file (probably stdin == NULL given the symptoms, but that's
just a guess)

A sanity check on stdin should then be possible near the
start of the main function.
msg19869 - (view) Author: Martin Pool (mbp) Date: 2005-06-06 05:20
Logged In: YES 

I doubt if libc checks whether the input is a directory;
there are possible (though extremely obscure) cases where
you might want to do that.

I think you probably need something along the lines of
fstat(0, &buf), then check the st_mode.  Remember that fifos
and chardevs ought to be allowed.
msg19870 - (view) Author: Martin Pool (mbp) Date: 2005-06-06 05:32
Logged In: YES 

Here is another failure, which might have the same root cause:

$ python /tmp
$ echo $?

I'd expect this to give an error.
msg19871 - (view) Author: Neal Norwitz (nnorwitz) * (Python committer) Date: 2005-10-03 01:05
Logged In: YES 

I fixed this problem and also added a warning when passing a
directory on the command line.  Before the fix, python would
just silently exit which just bit me recently.  (Same as
mbp's comment.)

Checked in as:
 * Misc/NEWS: 1.1384, 1.1193.2.118
 * Modules/main.c: 1.85,
 * Python/sysmodule.c: 2.130,
 * Lib/test/ 1.1,
Date User Action Args
2022-04-11 14:56:02adminsetgithub: 39883
2004-01-31 00:42:27inyeolcreate