diff options
| author | Benoit Hudson <benoit@imgspc.com> | 2019-12-06 14:15:03 -0500 | 
|---|---|---|
| committer | Victor Stinner <vstinner@python.org> | 2019-12-06 20:15:03 +0100 | 
| commit | 723f71abf7ab0a7be394f9f7b2daa9ecdf6fb1eb (patch) | |
| tree | ab89f9828245437a062c18bd46b04b29cc60a603 /Modules/posixmodule.c | |
| parent | e76ee1a72b9e3f5da287663ea3daec4bb3f67612 (diff) | |
| download | cpython-git-723f71abf7ab0a7be394f9f7b2daa9ecdf6fb1eb.tar.gz | |
bpo-37931: Fix crash on OSX re-initializing os.environ (GH-15428)
On most platforms, the `environ` symbol is accessible everywhere.
In a dylib on OSX, it's not easily accessible, you need to find it with
_NSGetEnviron.
The code was caching the *value* of environ. But a setenv() can change the value,
leaving garbage at the old value. Fix: don't cache the value of environ, just
read it every time.
Diffstat (limited to 'Modules/posixmodule.c')
| -rw-r--r-- | Modules/posixmodule.c | 10 | 
1 files changed, 5 insertions, 5 deletions
| diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c index 8985471137..322c215981 100644 --- a/Modules/posixmodule.c +++ b/Modules/posixmodule.c @@ -1402,7 +1402,6 @@ win32_get_reparse_tag(HANDLE reparse_point_handle, ULONG *reparse_tag)  ** man environ(7).  */  #include <crt_externs.h> -static char **environ;  #elif !defined(_MSC_VER) && (!defined(__WATCOMC__) || defined(__QNX__) || defined(__VXWORKS__))  extern char **environ;  #endif /* !_MSC_VER */ @@ -1420,15 +1419,16 @@ convertenviron(void)      d = PyDict_New();      if (d == NULL)          return NULL; -#if defined(WITH_NEXT_FRAMEWORK) || (defined(__APPLE__) && defined(Py_ENABLE_SHARED)) -    if (environ == NULL) -        environ = *_NSGetEnviron(); -#endif  #ifdef MS_WINDOWS      /* _wenviron must be initialized in this way if the program is started         through main() instead of wmain(). */      _wgetenv(L"");      e = _wenviron; +#elif defined(WITH_NEXT_FRAMEWORK) || (defined(__APPLE__) && defined(Py_ENABLE_SHARED)) +    /* environ is not accessible as an extern in a shared object on OSX; use +       _NSGetEnviron to resolve it. The value changes if you add environment +       variables between calls to Py_Initialize, so don't cache the value. */ +    e = *_NSGetEnviron();  #else      e = environ;  #endif | 
