diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2017-06-23 17:17:38 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-06-23 17:17:38 (GMT) |
commit | e7135751b8e48af80665e40ac8fa6d0073e5affe (patch) | |
tree | 3ab00867f840f76a6669fb492fb5833f4253a57d /Lib/subprocess.py | |
parent | 1b7474dedcbbd731a362b17abfbd7e5a60b64f63 (diff) | |
download | cpython-e7135751b8e48af80665e40ac8fa6d0073e5affe.zip cpython-e7135751b8e48af80665e40ac8fa6d0073e5affe.tar.gz cpython-e7135751b8e48af80665e40ac8fa6d0073e5affe.tar.bz2 |
[3.6] bpo-30730: Prevent environment variables injection in subprocess on Windows. (GH-2325) (#2360)
Prevent passing other invalid environment variables and command arguments..
(cherry picked from commit d174d24a5d37d1516b885dc7c82f71ecd5930700)
Diffstat (limited to 'Lib/subprocess.py')
-rw-r--r-- | Lib/subprocess.py | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/Lib/subprocess.py b/Lib/subprocess.py index e626a8a..b790cbd 100644 --- a/Lib/subprocess.py +++ b/Lib/subprocess.py @@ -1239,8 +1239,12 @@ class Popen(object): # and pass it to fork_exec() if env is not None: - env_list = [os.fsencode(k) + b'=' + os.fsencode(v) - for k, v in env.items()] + env_list = [] + for k, v in env.items(): + k = os.fsencode(k) + if b'=' in k: + raise ValueError("illegal environment variable name") + env_list.append(k + b'=' + os.fsencode(v)) else: env_list = None # Use execv instead of execve. executable = os.fsencode(executable) |