[2.7] bpo-30730: Prevent environment variables injection in subproces… · python/cpython@9dda2ca · GitHub
Skip to content

Commit 9dda2ca

Browse files
[2.7] bpo-30730: Prevent environment variables injection in subprocess on Windows. (GH-2325) (#2372)
Prevent passing other invalid environment variables and command arguments.. (cherry picked from commit d174d24)
1 parent 7709b4d commit 9dda2ca

4 files changed

Lines changed: 63 additions & 2 deletions

File tree

Lib/test/test_subprocess.py

Lines changed: 40 additions & 0 deletions

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ Extension Modules
5252
Library
5353
-------
5454

55+
- [Security] bpo-30730: Prevent environment variables injection in subprocess on
56+
Windows. Prevent passing other environment variables and command arguments.
57+
5558
- [Security] bpo-30694: Upgrade expat copy from 2.2.0 to 2.2.1 to get fixes
5659
of multiple security vulnerabilities including: CVE-2017-9233 (External
5760
entity infinite loop DoS), CVE-2016-9063 (Integer overflow, re-fix),

Modules/posixmodule.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3315,6 +3315,12 @@ posix_execve(PyObject *self, PyObject *args)
33153315
{
33163316
goto fail_2;
33173317
}
3318+
/* Search from index 1 because on Windows starting '=' is allowed for
3319+
defining hidden environment variables. */
3320+
if (*k == '\0' || strchr(k + 1, '=') != NULL) {
3321+
PyErr_SetString(PyExc_ValueError, "illegal environment variable name");
3322+
goto fail_2;
3323+
}
33183324

33193325
#if defined(PYOS_OS2)
33203326
/* Omit Pseudo-Env Vars that Would Confuse Programs if Passed On */

PC/_subprocess.c

Lines changed: 14 additions & 2 deletions

0 commit comments

Comments
 (0)