mirror of
https://gitlab.com/ita1024/waf.git
synced 2024-11-25 11:19:52 +01:00
Prevent pre-forked process to access the standard input of their parents
This commit is contained in:
parent
7af93bc8a3
commit
22738deb0e
@ -903,7 +903,7 @@ def get_process():
|
|||||||
except IndexError:
|
except IndexError:
|
||||||
filepath = os.path.dirname(os.path.abspath(__file__)) + os.sep + 'processor.py'
|
filepath = os.path.dirname(os.path.abspath(__file__)) + os.sep + 'processor.py'
|
||||||
cmd = [sys.executable, '-c', readf(filepath)]
|
cmd = [sys.executable, '-c', readf(filepath)]
|
||||||
return subprocess.Popen(cmd, stdout=subprocess.PIPE, stdin=subprocess.PIPE, bufsize=0, close_fds=not is_win32)
|
return subprocess.Popen(cmd, stdout=subprocess.PIPE, stdin=subprocess.PIPE)
|
||||||
|
|
||||||
def run_prefork_process(cmd, kwargs, cargs):
|
def run_prefork_process(cmd, kwargs, cargs):
|
||||||
"""
|
"""
|
||||||
@ -911,6 +911,11 @@ def run_prefork_process(cmd, kwargs, cargs):
|
|||||||
"""
|
"""
|
||||||
if not kwargs.get('env'):
|
if not kwargs.get('env'):
|
||||||
kwargs['env'] = dict(os.environ)
|
kwargs['env'] = dict(os.environ)
|
||||||
|
|
||||||
|
if hasattr(subprocess, 'DEVNULL') and 'stdin' not in kwargs:
|
||||||
|
# prevent accidental communication errors
|
||||||
|
kwargs['stdin'] = subprocess.DEVNULL
|
||||||
|
|
||||||
try:
|
try:
|
||||||
obj = base64.b64encode(cPickle.dumps([cmd, kwargs, cargs]))
|
obj = base64.b64encode(cPickle.dumps([cmd, kwargs, cargs]))
|
||||||
except (TypeError, AttributeError):
|
except (TypeError, AttributeError):
|
||||||
@ -1011,7 +1016,7 @@ def run_process(cmd, kwargs, cargs={}):
|
|||||||
or falling back to subprocess.Popen. See :py:func:`waflib.Utils.run_prefork_process`
|
or falling back to subprocess.Popen. See :py:func:`waflib.Utils.run_prefork_process`
|
||||||
and :py:func:`waflib.Utils.run_regular_process`
|
and :py:func:`waflib.Utils.run_regular_process`
|
||||||
"""
|
"""
|
||||||
if kwargs.get('stdout') and kwargs.get('stderr'):
|
if kwargs.get('stdout') and kwargs.get('stderr') and 'stdin' not in kwargs:
|
||||||
return run_prefork_process(cmd, kwargs, cargs)
|
return run_prefork_process(cmd, kwargs, cargs)
|
||||||
else:
|
else:
|
||||||
return run_regular_process(cmd, kwargs, cargs)
|
return run_regular_process(cmd, kwargs, cargs)
|
||||||
@ -1051,14 +1056,6 @@ def atexit_pool():
|
|||||||
if (sys.hexversion<0x207000f and not is_win32) or sys.hexversion>=0x306000f:
|
if (sys.hexversion<0x207000f and not is_win32) or sys.hexversion>=0x306000f:
|
||||||
atexit.register(atexit_pool)
|
atexit.register(atexit_pool)
|
||||||
|
|
||||||
try:
|
if os.environ.get('WAF_NO_PREFORK') or sys.platform == 'cli' or not sys.executable or not hasattr(subprocess, 'DEVNULL'):
|
||||||
# proc.stdin.readline errors
|
|
||||||
import sysconfig
|
|
||||||
bad_stdin = 'mingw' in sysconfig.get_platform()
|
|
||||||
except ImportError:
|
|
||||||
bad_stdin = True
|
|
||||||
|
|
||||||
if bad_stdin or os.environ.get('WAF_NO_PREFORK') or sys.platform == 'cli' or not sys.executable:
|
|
||||||
run_process = run_regular_process
|
run_process = run_regular_process
|
||||||
get_process = alloc_process_pool = nada
|
get_process = alloc_process_pool = nada
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user