[New-bugs-announce] [issue32844] subprocess may incorrectly redirect a low fd to stderr if another low fd is closed

Alexey Izbyshev report at bugs.python.org
Wed Feb 14 16:10:48 EST 2018


New submission from Alexey Izbyshev <izbyshev at ispras.ru>:

When redirecting, subprocess attempts to achieve the following state: each fd to be redirected to is less than or equal to the fd it is redirected from, which is necessary because redirection occurs in the ascending order of destination descriptors. It fails to do so if a low fd (< 2) is redirected to stderr and another low fd is closed, which may lead to an incorrect redirection, for example:

$ cat test.py
import os
import subprocess
import sys

os.close(0)

subprocess.call([sys.executable, '-c',
                 'import sys; print("Hello", file=sys.stderr)'],
                stdin=2,
                stderr=1)

$ python3 test.py 2>/dev/null
$ python3 test.py >/dev/null
Hello

Expected behavior:
$ python3 test.py >/dev/null
$ python3 test.py 2>/dev/null
Hello

----------
components: Extension Modules, Library (Lib)
messages: 312181
nosy: gregory.p.smith, izbyshev
priority: normal
severity: normal
status: open
title: subprocess may incorrectly redirect a low fd to stderr if another low fd is closed
type: behavior
versions: Python 3.6, Python 3.7

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue32844>
_______________________________________


More information about the New-bugs-announce mailing list