summaryrefslogtreecommitdiffstats
path: root/Lib/subprocess.py
diff options
context:
space:
mode:
authorAmmar Askar <ammar_askar@hotmail.com>2017-09-06 06:41:30 (GMT)
committerGregory P. Smith <greg@krypto.org>2017-09-06 06:41:30 (GMT)
commit3fc499bca18454b9f432b9b0106cab662bfeb549 (patch)
tree294f00f9922bff52dad0fea08afd8d28db45a3f5 /Lib/subprocess.py
parent6877111648ac3e042ee5d0458cbeb65dd1a84b2d (diff)
downloadcpython-3fc499bca18454b9f432b9b0106cab662bfeb549.zip
cpython-3fc499bca18454b9f432b9b0106cab662bfeb549.tar.gz
cpython-3fc499bca18454b9f432b9b0106cab662bfeb549.tar.bz2
bpo-31178: Avoid concatenating bytes with str in subprocess error (#3066)
Avoid concatenating bytes with str in the typically rare subprocess error path (exec failed). Includes a mock based unittest to exercise the codepath.
Diffstat (limited to 'Lib/subprocess.py')
-rw-r--r--Lib/subprocess.py9
1 files changed, 6 insertions, 3 deletions
diff --git a/Lib/subprocess.py b/Lib/subprocess.py
index bafb501..25e5698 100644
--- a/Lib/subprocess.py
+++ b/Lib/subprocess.py
@@ -1313,15 +1313,18 @@ class Popen(object):
try:
exception_name, hex_errno, err_msg = (
errpipe_data.split(b':', 2))
+ # The encoding here should match the encoding
+ # written in by the subprocess implementations
+ # like _posixsubprocess
+ err_msg = err_msg.decode()
except ValueError:
exception_name = b'SubprocessError'
hex_errno = b'0'
- err_msg = (b'Bad exception data from child: ' +
- repr(errpipe_data))
+ err_msg = 'Bad exception data from child: {!r}'.format(
+ bytes(errpipe_data))
child_exception_type = getattr(
builtins, exception_name.decode('ascii'),
SubprocessError)
- err_msg = err_msg.decode(errors="surrogatepass")
if issubclass(child_exception_type, OSError) and hex_errno:
errno_num = int(hex_errno, 16)
child_exec_never_called = (err_msg == "noexec")