]> granicus.if.org Git - php/commitdiff
Ensure that we don't close a random fd
authorSascha Schumann <sas@php.net>
Tue, 13 May 2003 02:25:29 +0000 (02:25 +0000)
committerSascha Schumann <sas@php.net>
Tue, 13 May 2003 02:25:29 +0000 (02:25 +0000)
fchdir(0)                                       Err#20 ENOTDIR
close(0)                                        = 0

main/main.c

index 0aab6236c02f0aed5cf05be7f2b612c924da2b39..df4f073e8c3b033c5e7ed87831ac637683a877af 100644 (file)
@@ -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);