[New-bugs-announce] [issue3144] popen / popen inconsistent fd behavior
report at bugs.python.org
Thu Jun 19 21:18:29 CEST 2008
New submission from Justin Cappos <justincappos at hotmail.com>:
The behavior of popen vs popen[2-4] differs with respect to open file
descriptors (at least on the Linux implementation of popen). popen
does not close file descriptors, thus processes retain open file
descriptors from their parent. This is likely not desirable for
security and stability reasons.
If this isn't fixed, at a minimum it would be a good thing to document.
Here is an example that demonstrates the issue:
<<< start of open_and_popen.py>>>
# This will not be printed if popen closes file descriptors
myfd = os.open("open_and_popen.py",os.O_RDONLY)
readfo = os.popen("python print_from_fd.py "+str(myfd),"r")
print "os.popen results in:"
# it will print the first line of the file here
(junkinfo, readfo) = os.popen2("python print_from_fd.py "+str(myfd),"r")
print "os.popen2 results in:"
# the child got an error, so this is just the error text
<<< end of open_and_popen.py>>>
<<< start of print_from_fd.py>>>
<<< end of print_from_fd.py>>>
components: Library (Lib)
title: popen / popen inconsistent fd behavior
Python tracker <report at bugs.python.org>
More information about the New-bugs-announce