From: Sascha Schumann Date: Tue, 13 May 2003 02:25:29 +0000 (+0000) Subject: Ensure that we don't close a random fd X-Git-Tag: php-4.3.2RC3~41 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=10f2defb0494f975b26063fb387d70d2cf543164;p=php Ensure that we don't close a random fd fchdir(0) Err#20 ENOTDIR close(0) = 0 --- diff --git a/main/main.c b/main/main.c index 0aab6236c0..df4f073e8c 100644 --- a/main/main.c +++ b/main/main.c @@ -1564,7 +1564,7 @@ PHPAPI int php_execute_script(zend_file_handle *primary_file TSRMLS_DC) zend_file_handle *prepend_file_p, *append_file_p; zend_file_handle prepend_file, append_file; #if HAVE_BROKEN_GETCWD - int old_cwd_fd; + int old_cwd_fd = -1; #else char *old_cwd; #endif @@ -1648,8 +1648,10 @@ PHPAPI int php_execute_script(zend_file_handle *primary_file TSRMLS_DC) } zend_end_try(); #if HAVE_BROKEN_GETCWD - fchdir(old_cwd_fd); - close(old_cwd_fd); + if (old_cwd_fd != -1) { + fchdir(old_cwd_fd); + close(old_cwd_fd); + } #else if (old_cwd[0] != '\0') { VCWD_CHDIR(old_cwd);