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: popen / popen[234] inconsistent fd behavior
Type: security Stage:
Components: Library (Lib) Versions:
Status: closed Resolution: out of date
Dependencies: Superseder:
Assigned To: Nosy List: amaury.forgeotdarc, justincappos
Priority: normal Keywords:

Created on 2008-06-19 19:18 by justincappos, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (2)
msg68416 - (view) Author: Justin Cappos (justincappos) Date: 2008-06-19 19:18
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>>>
# This will not be printed if popen closes file descriptors

import os
myfd ="",os.O_RDONLY)

readfo = os.popen("python "+str(myfd),"r")

print "os.popen results in:"
# it will print the first line of the file here

(junkinfo, readfo) = os.popen2("python "+str(myfd),"r")

print "os.popen2 results in:"
# the child got an error, so this is just the error text

<<< end of>>>

<<< start of>>>
import os
import sys
<<< end of>>>
msg68418 - (view) Author: Amaury Forgeot d'Arc (amaury.forgeotdarc) * (Python committer) Date: 2008-06-19 19:32
This is so true that these functions are now documented as deprecated:

Please use the subprocess.Popen class instead, which gives a much better
interface to processes.
Date User Action Args
2022-04-11 14:56:35adminsetgithub: 47394
2008-06-19 19:32:30amaury.forgeotdarcsetstatus: open -> closed
resolution: out of date
messages: + msg68418
nosy: + amaury.forgeotdarc
2008-06-19 19:18:27justincapposcreate