Author: Armin Rigo <[email protected]>
Branch: py3.6
Changeset: r98436:1697fc0bff5d
Date: 2020-01-02 11:07 +0100
http://bitbucket.org/pypy/pypy/changeset/1697fc0bff5d/
Log: Issue 3136: Windows: os.putenv()
diff --git a/pypy/module/posix/interp_posix.py
b/pypy/module/posix/interp_posix.py
--- a/pypy/module/posix/interp_posix.py
+++ b/pypy/module/posix/interp_posix.py
@@ -909,11 +909,20 @@
@unwrap_spec(name=unicode, value=unicode)
def putenv(space, name, value):
"""Change or add an environment variable."""
+ # Search from index 1 because on Windows starting '=' is allowed for
+ # defining hidden environment variables.
+ if len(name) == 0 or u'=' in name[1:]:
+ raise oefmt(space.w_ValueError, "illegal environment variable
name")
+
# len includes space for '=' and a trailing NUL
if len(name) + len(value) + 2 > rwin32._MAX_ENV:
raise oefmt(space.w_ValueError,
"the environment variable is longer than %d "
"characters", rwin32._MAX_ENV)
+
+ if u'\x00' in name or u'\x00' in value:
+ raise oefmt(space.w_ValueError, "embedded null character")
+
try:
rwin32._wputenv(name, value)
except OSError as e:
diff --git a/pypy/module/posix/test/test_interp_posix.py
b/pypy/module/posix/test/test_interp_posix.py
--- a/pypy/module/posix/test/test_interp_posix.py
+++ b/pypy/module/posix/test/test_interp_posix.py
@@ -69,3 +69,9 @@
cc = os.cpu_count()
assert cc is None or (isinstance(cc, int) and cc > 0)
"""
+
+ def test_putenv_invalid_name(self):
+ """
+ import os
+ raises(ValueError, os.putenv, "foo=bar", "xxx")
+ """
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit