bpo-30065: Fixed arguments validation in _posixsubprocess.fork_exec()… · pythoncapi/cpython@66bffd1 · GitHub
Skip to content

Commit 66bffd1

Browse files
bpo-30065: Fixed arguments validation in _posixsubprocess.fork_exec(). (python#1110)
1 parent a79f4c2 commit 66bffd1

5 files changed

Lines changed: 41 additions & 26 deletions

File tree

Lib/multiprocessing/util.py

Lines changed: 1 addition & 1 deletion

Lib/subprocess.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1252,7 +1252,8 @@ def _execute_child(self, args, executable, preexec_fn, close_fds,
12521252
fds_to_keep.add(errpipe_write)
12531253
self.pid = _posixsubprocess.fork_exec(
12541254
args, executable_list,
1255-
close_fds, sorted(fds_to_keep), cwd, env_list,
1255+
close_fds, tuple(sorted(map(int, fds_to_keep))),
1256+
cwd, env_list,
12561257
p2cread, p2cwrite, c2pread, c2pwrite,
12571258
errread, errwrite,
12581259
errpipe_read, errpipe_write,

Lib/test/test_capi.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,15 +98,15 @@ class Z(object):
9898
def __len__(self):
9999
return 1
100100
self.assertRaises(TypeError, _posixsubprocess.fork_exec,
101-
1,Z(),3,[1, 2],5,6,7,8,9,10,11,12,13,14,15,16,17)
101+
1,Z(),3,(1, 2),5,6,7,8,9,10,11,12,13,14,15,16,17)
102102
# Issue #15736: overflow in _PySequence_BytesToCharpArray()
103103
class Z(object):
104104
def __len__(self):
105105
return sys.maxsize
106106
def __getitem__(self, i):
107107
return b'x'
108108
self.assertRaises(MemoryError, _posixsubprocess.fork_exec,
109-
1,Z(),3,[1, 2],5,6,7,8,9,10,11,12,13,14,15,16,17)
109+
1,Z(),3,(1, 2),5,6,7,8,9,10,11,12,13,14,15,16,17)
110110

111111
@unittest.skipUnless(_posixsubprocess, '_posixsubprocess required for this test.')
112112
def test_subprocess_fork_exec(self):
@@ -116,7 +116,7 @@ def __len__(self):
116116

117117
# Issue #15738: crash in subprocess_fork_exec()
118118
self.assertRaises(TypeError, _posixsubprocess.fork_exec,
119-
Z(),[b'1'],3,[1, 2],5,6,7,8,9,10,11,12,13,14,15,16,17)
119+
Z(),[b'1'],3,(1, 2),5,6,7,8,9,10,11,12,13,14,15,16,17)
120120

121121
@unittest.skipIf(MISSING_C_DOCSTRINGS,
122122
"Signature information for builtins requires docstrings")

Lib/test/test_subprocess.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2418,7 +2418,7 @@ def test_fork_exec(self):
24182418
with self.assertRaises(TypeError):
24192419
_posixsubprocess.fork_exec(
24202420
args, exe_list,
2421-
True, [], cwd, env_list,
2421+
True, (), cwd, env_list,
24222422
-1, -1, -1, -1,
24232423
1, 2, 3, 4,
24242424
True, True, func)
@@ -2430,6 +2430,16 @@ def test_fork_exec(self):
24302430
def test_fork_exec_sorted_fd_sanity_check(self):
24312431
# Issue #23564: sanity check the fork_exec() fds_to_keep sanity check.
24322432
import _posixsubprocess
2433+
class BadInt:
2434+
first = True
2435+
def __init__(self, value):
2436+
self.value = value
2437+
def __int__(self):
2438+
if self.first:
2439+
self.first = False
2440+
return self.value
2441+
raise ValueError
2442+
24332443
gc_enabled = gc.isenabled()
24342444
try:
24352445
gc.enable()
@@ -2440,6 +2450,7 @@ def test_fork_exec_sorted_fd_sanity_check(self):
24402450
(18, 23, 42, 2**63), # Out of range.
24412451
(5, 4), # Not sorted.
24422452
(6, 7, 7, 8), # Duplicate.
2453+
(BadInt(1), BadInt(2)),
24432454
):
24442455
with self.assertRaises(
24452456
ValueError,

Modules/_posixsubprocess.c

Lines changed: 23 additions & 20 deletions

0 commit comments

Comments
 (0)