[pypy-commit] pypy py3.6: make putenv complain about bad names (test already existed)

cfbolz pypy.commits at gmail.com
Sun Feb 2 12:49:40 EST 2020


Author: Carl Friedrich Bolz-Tereick <cfbolz at gmx.de>
Branch: py3.6
Changeset: r98643:23ce279ad084
Date: 2020-01-31 23:29 +0100
http://bitbucket.org/pypy/pypy/changeset/23ce279ad084/

Log:	make putenv complain about bad names (test already existed) (grafted
	from 89255ed57e9fa884c8bbeb50f19f2194b4fe698f)

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
@@ -943,9 +943,21 @@
     def putenv(space, w_name, w_value):
         """Change or add an environment variable."""
         try:
-            dispatch_filename_2(rposix.putenv)(space, w_name, w_value)
+            dispatch_filename_2(putenv_impl)(space, w_name, w_value)
         except OSError as e:
             raise wrap_oserror(space, e, eintr_retry=False)
+        except ValueError:
+            raise oefmt(space.w_ValueError,
+                    "illegal environment variable name")
+
+    @specialize.argtype(0, 1)
+    def putenv_impl(name, value):
+        from rpython.rlib.rposix import _as_bytes
+        name = _as_bytes(name)
+        value = _as_bytes(value)
+        if "=" in name:
+            raise ValueError
+        return rposix.putenv(name, value)
 
     def unsetenv(space, w_name):
         """Delete an environment variable."""


More information about the pypy-commit mailing list