Bug #49753 [Opn->Csd]: Current directory in shutdown function leaks between requests
| From: | pollita@php.net | Date: | Sun, 14 May 2017 16:51:36 +0000 |
| Subject: | Bug #49753 [Opn->Csd]: Current directory in shutdown function leaks between requests | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-209106@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=49753&edit=1
ID: 49753
Updated by: pollita@php.net
Reported by: ant at specialops dot ath dot cx
Summary: Current directory in shutdown function leaks between
requests
-Status: Open
+Status: Closed
Type: Bug
Package: Scripting Engine problem
Operating System: Linux 2.6.30 (gentoo)
PHP Version: 5.3.0
-Assigned To:
+Assigned To: pollita
Block user comment: N
Private report: N
New Comment:
I'm fairly certain this is fixed in current PHP.
If I'm wrong, please feel free to reopen this bug report.
Please include webserver version and output of:
php -i | grep 'Configure
Command'
Previous Comments:
------------------------------------------------------------------------
[2009-10-12 01:00:00] php-bugs at lists dot php dot net
No feedback was provided for this bug for over a week, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
------------------------------------------------------------------------
[2009-10-07 16:38:54] ant at specialops dot ath dot cx
I've just tested it, and it does indeed fix the problem.
------------------------------------------------------------------------
[2009-10-04 15:21:57] kalle@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 https://bugs.php.net/bug.php?id=49753&edit=1