Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

segfault if redirecting directory #39883

Closed
inyeol mannequin opened this issue Jan 31, 2004 · 7 comments
Closed

segfault if redirecting directory #39883

inyeol mannequin opened this issue Jan 31, 2004 · 7 comments
Labels
interpreter-core (Objects, Python, Grammar, and Parser dirs)

Comments

@inyeol
Copy link
Mannequin

inyeol mannequin commented Jan 31, 2004

BPO 887946
Nosy @ncoghlan

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = None
closed_at = <Date 2005-10-03.01:05:12.000>
created_at = <Date 2004-01-31.00:42:27.000>
labels = ['interpreter-core']
title = 'segfault if redirecting directory'
updated_at = <Date 2005-10-03.01:05:12.000>
user = 'https://bugs.python.org/inyeol'

bugs.python.org fields:

activity = <Date 2005-10-03.01:05:12.000>
actor = 'nnorwitz'
assignee = 'nnorwitz'
closed = True
closed_date = None
closer = None
components = ['Interpreter Core']
creation = <Date 2004-01-31.00:42:27.000>
creator = 'inyeol'
dependencies = []
files = []
hgrepos = []
issue_num = 887946
keywords = []
message_count = 7.0
messages = ['19865', '19866', '19867', '19868', '19869', '19870', '19871']
nosy_count = 4.0
nosy_names = ['nnorwitz', 'inyeol', 'ncoghlan', 'mbp']
pr_nums = []
priority = 'high'
resolution = 'fixed'
stage = None
status = 'closed'
superseder = None
type = None
url = 'https://bugs.python.org/issue887946'
versions = ['Python 2.4']

@inyeol
Copy link
Mannequin Author

inyeol mannequin commented Jan 31, 2004

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

@inyeol inyeol mannequin closed this as completed Jan 31, 2004
@inyeol inyeol mannequin assigned nnorwitz Jan 31, 2004
@inyeol inyeol mannequin added the interpreter-core (Objects, Python, Grammar, and Parser dirs) label Jan 31, 2004
@inyeol inyeol mannequin closed this as completed Jan 31, 2004
@inyeol inyeol mannequin assigned nnorwitz Jan 31, 2004
@inyeol inyeol mannequin added the interpreter-core (Objects, Python, Grammar, and Parser dirs) label Jan 31, 2004
@inyeol
Copy link
Mannequin Author

inyeol mannequin commented Nov 4, 2004

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

@ncoghlan
Copy link
Contributor

Logged In: YES
user_id=1038590

Win XP SP 1 -

C:\Python24>python < Lib
"Access is Denied"

@ncoghlan
Copy link
Contributor

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.

@mbp
Copy link
Mannequin

mbp mannequin commented Jun 6, 2005

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.

@mbp
Copy link
Mannequin

mbp mannequin commented Jun 6, 2005

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.

@nnorwitz
Copy link
Mannequin

nnorwitz mannequin commented Oct 3, 2005

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:

@ezio-melotti ezio-melotti transferred this issue from another repository Apr 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
interpreter-core (Objects, Python, Grammar, and Parser dirs)
Projects
None yet
Development

No branches or pull requests

1 participant