ID:               49753
 Comment by:       ant at specialops dot ath dot cx
 Reported By:      ant at specialops dot ath dot cx
 Status:           Feedback
 Bug Type:         Scripting Engine problem
 Operating System: Linux 2.6.30 (gentoo)
 PHP Version:      5.3.0
 New Comment:

I've just tested it, and it does indeed fix the problem.


Previous Comments:
------------------------------------------------------------------------

[2009-10-04 15:21:57] ka...@php.net

We could store the cwd before trying to execute the shutdown handlers,
and then restore it to that dir after the handlers are executed. However
I'm not sure whether we should do this on per SAPI level or per function
implementation level, below patch patches it per function level.

Could you try apply this and see if it solves the problem?

Index: basic_functions.c
===================================================================
--- basic_functions.c   (revision 289184)
+++ basic_functions.c   (working copy)
@@ -5026,10 +5026,17 @@
 void php_call_shutdown_functions(TSRMLS_D) /* {{{ */
 {
        if (BG(user_shutdown_function_names)) {
+               char *cwd = getcwd(NULL, 0);
+
                zend_try {
                        zend_hash_apply(BG(user_shutdown_function_names), 
(apply_func_t)
user_shutdown_function_call TSRMLS_CC);
                }
                zend_end_try();
+
+               if (cwd) {
+                       chdir(cwd);
+               }
+
                php_free_shutdown_functions(TSRMLS_C);
        }
 }

------------------------------------------------------------------------

[2009-10-02 19:00:37] ant at specialops dot ath dot cx

Description:
------------
In 5.3.0 one of my scripts stopped working due to the behaviour
documented at the bottom of the register_shutdown_function page.

The actual problem is that if I change the directory in the shutdown
function, that change persists across requests and can end up in
completely unrelated scripts' shutdown function calls.

Reproduce code:
---------------
<?php
echo "Script A\n";
function test() {
    echo getcwd() . "\n";
    if ( file_exists('file.inc') ) {
        include 'file.inc';
    }
}
register_shutdown_function('test');
?>

<?php
echo "Script B\n";
function change() {
    chdir('/tmp/');
    file_put_contents('file.inc', '<?php echo "something nasty\n";
?>');
}
register_shutdown_function('change');
?>

Expected result:
----------------
Script A
/var/www/localhost/htdocs/
Script B
Script A
/var/www/localhost/htdocs/

Actual result:
--------------
Script A
/var/www/localhost/htdocs/
Script B
Script A
/tmp
something nasty


------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=49753&edit=1

Reply via email to