classification
Title: segfault if redirecting directory
Type: Stage:
Components: Interpreter Core Versions: Python 2.4
process
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 2005-10-03 01:05 by nnorwitz. 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
SUNW,Sun-Blade-1000
$ 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
foo/
$ python < foo
Segmentation Fault

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

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 
user_id=1038590

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 
user_id=1038590

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 
user_id=521

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 
user_id=521

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

$ python /tmp
$ echo $?
0

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 
user_id=33168

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, 1.84.2.1
 * Python/sysmodule.c: 2.130, 2.126.2.4
 * Lib/test/test_cmd_line.py: 1.1, 1.1.2.2
History
Date User Action Args
2004-01-31 00:42:27inyeolcreate