summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2017-04-19 21:51:05 (GMT)
committerGitHub <noreply@github.com>2017-04-19 21:51:05 (GMT)
commitc97c1914f401359f2a7e6c8e0364e71ad9fb5bc8 (patch)
treea7e32b42bc25420e1762b122d0405aff6f0b34e5 /Lib
parent952a05e4e2cf082b74a1676a2804f1f43a9b7702 (diff)
downloadcpython-c97c1914f401359f2a7e6c8e0364e71ad9fb5bc8.zip
cpython-c97c1914f401359f2a7e6c8e0364e71ad9fb5bc8.tar.gz
cpython-c97c1914f401359f2a7e6c8e0364e71ad9fb5bc8.tar.bz2
[3.5] bpo-30065: Fixed arguments validation in _posixsubprocess.fork_exec(). (GH-1110) (#1190)
(cherry picked from commit 66bffd1)
Diffstat (limited to 'Lib')
-rw-r--r--Lib/multiprocessing/util.py2
-rw-r--r--Lib/subprocess.py3
-rw-r--r--Lib/test/test_capi.py6
-rw-r--r--Lib/test/test_subprocess.py13
4 files changed, 18 insertions, 6 deletions
diff --git a/Lib/multiprocessing/util.py b/Lib/multiprocessing/util.py
index 1a2c0db..0ce274c 100644
--- a/Lib/multiprocessing/util.py
+++ b/Lib/multiprocessing/util.py
@@ -386,7 +386,7 @@ def _close_stdin():
def spawnv_passfds(path, args, passfds):
import _posixsubprocess
- passfds = sorted(passfds)
+ passfds = tuple(sorted(map(int, passfds)))
errpipe_read, errpipe_write = os.pipe()
try:
return _posixsubprocess.fork_exec(
diff --git a/Lib/subprocess.py b/Lib/subprocess.py
index 2165524..281ea8a 100644
--- a/Lib/subprocess.py
+++ b/Lib/subprocess.py
@@ -1214,7 +1214,8 @@ class Popen(object):
fds_to_keep.add(errpipe_write)
self.pid = _posixsubprocess.fork_exec(
args, executable_list,
- close_fds, sorted(fds_to_keep), cwd, env_list,
+ close_fds, tuple(sorted(map(int, fds_to_keep))),
+ cwd, env_list,
p2cread, p2cwrite, c2pread, c2pwrite,
errread, errwrite,
errpipe_read, errpipe_write,
diff --git a/Lib/test/test_capi.py b/Lib/test/test_capi.py
index 1eadd22..042e5aa 100644
--- a/Lib/test/test_capi.py
+++ b/Lib/test/test_capi.py
@@ -96,7 +96,7 @@ class CAPITest(unittest.TestCase):
def __len__(self):
return 1
self.assertRaises(TypeError, _posixsubprocess.fork_exec,
- 1,Z(),3,[1, 2],5,6,7,8,9,10,11,12,13,14,15,16,17)
+ 1,Z(),3,(1, 2),5,6,7,8,9,10,11,12,13,14,15,16,17)
# Issue #15736: overflow in _PySequence_BytesToCharpArray()
class Z(object):
def __len__(self):
@@ -104,7 +104,7 @@ class CAPITest(unittest.TestCase):
def __getitem__(self, i):
return b'x'
self.assertRaises(MemoryError, _posixsubprocess.fork_exec,
- 1,Z(),3,[1, 2],5,6,7,8,9,10,11,12,13,14,15,16,17)
+ 1,Z(),3,(1, 2),5,6,7,8,9,10,11,12,13,14,15,16,17)
@unittest.skipUnless(_posixsubprocess, '_posixsubprocess required for this test.')
def test_subprocess_fork_exec(self):
@@ -114,7 +114,7 @@ class CAPITest(unittest.TestCase):
# Issue #15738: crash in subprocess_fork_exec()
self.assertRaises(TypeError, _posixsubprocess.fork_exec,
- Z(),[b'1'],3,[1, 2],5,6,7,8,9,10,11,12,13,14,15,16,17)
+ Z(),[b'1'],3,(1, 2),5,6,7,8,9,10,11,12,13,14,15,16,17)
@unittest.skipIf(MISSING_C_DOCSTRINGS,
"Signature information for builtins requires docstrings")
diff --git a/Lib/test/test_subprocess.py b/Lib/test/test_subprocess.py
index 2dc03ee..03a06e0 100644
--- a/Lib/test/test_subprocess.py
+++ b/Lib/test/test_subprocess.py
@@ -2371,7 +2371,7 @@ class POSIXProcessTestCase(BaseTestCase):
with self.assertRaises(TypeError):
_posixsubprocess.fork_exec(
args, exe_list,
- True, [], cwd, env_list,
+ True, (), cwd, env_list,
-1, -1, -1, -1,
1, 2, 3, 4,
True, True, func)
@@ -2383,6 +2383,16 @@ class POSIXProcessTestCase(BaseTestCase):
def test_fork_exec_sorted_fd_sanity_check(self):
# Issue #23564: sanity check the fork_exec() fds_to_keep sanity check.
import _posixsubprocess
+ class BadInt:
+ first = True
+ def __init__(self, value):
+ self.value = value
+ def __int__(self):
+ if self.first:
+ self.first = False
+ return self.value
+ raise ValueError
+
gc_enabled = gc.isenabled()
try:
gc.enable()
@@ -2393,6 +2403,7 @@ class POSIXProcessTestCase(BaseTestCase):
(18, 23, 42, 2**63), # Out of range.
(5, 4), # Not sorted.
(6, 7, 7, 8), # Duplicate.
+ (BadInt(1), BadInt(2)),
):
with self.assertRaises(
ValueError,