Skip to content

Conversation

@keyurdg
Copy link
Contributor

@keyurdg keyurdg commented Mar 29, 2013

The process title change module keeps track of the locally allocated
environ, so it doesn't need to worry about when environ changes
underneath it, for example by putenv()/setenv()

The process title change module keeps track of the locally allocated
environ, so it doesn't need to worry about when environ changes
underneath it, for example by putenv()/setenv()
@keyurdg
Copy link
Contributor Author

keyurdg commented Mar 29, 2013

Merged this pull request.

@keyurdg keyurdg closed this Mar 29, 2013
@laruence
Copy link
Member

@keyurdg the frozen_environ is needed,, otherwise when a item in env is update, you will get invalid free.

<?php

putenv("HOME=/tmp");
var_dump(getenv("HOME"));

putenv("FOO=BAR");
var_dump(getenv("FOO"));

I will commit my patch.. thanks

@keyurdg
Copy link
Contributor Author

keyurdg commented Mar 29, 2013

@laruence Great catch, I now realized my mistake.

For anyone else curious: putenv() will create a whole new environment if the 'key' doesn't already exist in the current environment and replace the global variable "environ" with this newly created one. To correctly handle the free'ing around the environ allocated by ps_title, new_environ is needed.

Or if the key does exist, putenv() will replace the pointer in the global environ with the string pointer passed in. To ensure correctness, frozen_environ stores a list of all strings alloc'ed by ps_title.c and frees them all at the end.

@laruence
Copy link
Member

yes, and more important is, zif_putenv passes in a string that is emalloced, if cleanup_ps_args attempt to free it -> invalid free

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