Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix getenv()/putenv() glitches on Windows #5730

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

cmb69
Copy link
Member

@cmb69 cmb69 commented Jun 17, 2020

We fix some wrong assumptions regarding GetEnvironmentVariableW()s
return value; although the comment got it right, the implementation
did not.

We also attempt to improve our putenv() implementation. The problem
that the underlying _putenv() is not thread-safe is no longer an
issue, since there are mutexes in place. This fixes the ZTS part of
bug #66265.

However, calling _putenv() after SetEnvironmentVariable() causes
issues regarding empty strings as variable values, because _putenv()
does not support that (instead, it removes the variable from the
environment). Therefore we swap both calls.

@cmb69 cmb69 marked this pull request as draft June 17, 2020 14:10
We fix some wrong assumptions regarding `GetEnvironmentVariableW()`s
return value; although the comment got it right, the implementation
did not.

We also attempt to improve our `putenv()` implementation.  The problem
that the underlying `_putenv()` is not thread-safe is no longer an
issue, since there are mutexes in place.  This fixes the ZTS part of
bug #66265.

However, calling `_putenv()` after `SetEnvironmentVariable()` causes
issues regarding empty strings as variable values, because `_putenv()`
does not support that (instead, it removes the variable from the
environment).  Therefore we swap both calls.
@cmb69 cmb69 changed the title Call _wputenv_s() also in ZTS builds Fix getenv()/putenv() glitches on Windows Jun 22, 2020
@cmb69 cmb69 marked this pull request as ready for review June 22, 2020 20:48
efree(pe.putenv_string);
efree(pe.key);
free(keyw);
free(valw);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This whole code is a big mess and we fail to unlock in this branch.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! I fixed the latter with 32257ac (PHP-7.4), and will have a look at cleaning up the code as soon as possible.

@cmb69 cmb69 marked this pull request as draft June 24, 2020 09:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants