summaryrefslogtreecommitdiffstats
path: root/Lib/subprocess.py
diff options
context:
space:
mode:
authorGregory P. Smith <greg@krypto.org>2017-09-06 20:34:17 (GMT)
committerGitHub <noreply@github.com>2017-09-06 20:34:17 (GMT)
commit3bad1650a03fdc8cfdd4cce154e1b2c07e3e4fa0 (patch)
tree74d19d67b8a7757c13cb75f4e1119559f1a98867 /Lib/subprocess.py
parent3aea3c298b510fffac0f33195c7380a19c60f4e2 (diff)
downloadcpython-3bad1650a03fdc8cfdd4cce154e1b2c07e3e4fa0.zip
cpython-3bad1650a03fdc8cfdd4cce154e1b2c07e3e4fa0.tar.gz
cpython-3bad1650a03fdc8cfdd4cce154e1b2c07e3e4fa0.tar.bz2
[3.6] bpo-31178: Avoid concatenating bytes with str in subprocess error (GH-3066) (#3388)
Avoid concatenating bytes with str in the typically rare subprocess error path (exec failed). Includes a mock based unittest to exercise the codepath. (cherry picked from commit 3fc499bca18454b9f432b9b0106cab662bfeb549)
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 d013234..575413d 100644
--- a/Lib/subprocess.py
+++ b/Lib/subprocess.py
@@ -1314,15 +1314,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")