Skip to content

Commit 56fac96

Browse files
committed
partially fixed bug #66265
NTS mode should additionally use _putenv to satisfy libs like gettext relying on _getenv. As _putenv isn't thread safe, it wouldn't bring much for the TS mode as it would change locale across all the threads and require locking to avoid random fails with concurrent _getenv calls.
1 parent 502ce90 commit 56fac96

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

‎ext/standard/basic_functions.c‎

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4138,13 +4138,17 @@ PHP_FUNCTION(putenv)
41384138
if (putenv(pe.putenv_string) == 0) { /* success */
41394139
# else
41404140
error_code = SetEnvironmentVariable(pe.key, value);
4141-
# if _MSC_VER < 1500
4142-
/* Yet another VC6 bug, unset may return env not found */
4143-
if (error_code != 0 ||
4144-
(error_code == 0 && GetLastError() == ERROR_ENVVAR_NOT_FOUND)) {
4145-
# else
4146-
if (error_code != 0) { /* success */
4147-
# endif
4141+
4142+
if (error_code != 0
4143+
# ifndef ZTS
4144+
/* We need both SetEnvironmentVariable and _putenv here as some
4145+
dependency lib could use either way to read the environment.
4146+
Obviously the CRT version will be useful more often. But
4147+
generally, doing both brings us on the safe track at least
4148+
in NTS build. */
4149+
&& _putenv(pe.putenv_string) == 0
4150+
# endif
4151+
) { /* success */
41484152
# endif
41494153
#endif
41504154
zend_hash_add(&BG(putenv_ht), pe.key, pe.key_len + 1, (void **) &pe, sizeof(putenv_entry), NULL);

0 commit comments

Comments
 (0)