-
Notifications
You must be signed in to change notification settings - Fork 7.8k
Potential deadlock when putenv fails #17403
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
Comments
Needs to be fixed for PHP-8.3+. |
Hi cmb69, thanks for your reply. Another issue is that the implementation of The The putenv C function does not copy the string that is passed in; instead, it directly stores the pointer in Thread 1: RINIT
putenv(env1)
pe.previous_value = NULL
// ... more code Thread 2: env1 and env2 have the same key RINIT
putenv(env2)
pe.previous_value = env1 Thread 1: RSHUTDOWN
// php_putenv_destructor()
free(pe->putenv_string) // free env1 Thread 2: RSHUTDOWN
// php_putenv_destructor()
// pe->previous_value is env1
putenv(pe->previous_value) // This memory address has already been freed |
I understood the deadlock problem and made a PR for it. |
Description
https://github.com/php/php-src/blob/master/ext/standard/basic_functions.c#L846
The else branch of the
putenv
function does not calltsrm_env_unlock()
to release the lock, which could potentially lead to a deadlock.PHP Version
PHP 8.4
Operating System
Ubuntu 22.04
The text was updated successfully, but these errors were encountered: