diff options
Diffstat (limited to 'ext/standard/dir.c')
| -rw-r--r-- | ext/standard/dir.c | 33 |
1 files changed, 30 insertions, 3 deletions
diff --git a/ext/standard/dir.c b/ext/standard/dir.c index f6737ed1a..c65cd9f8f 100644 --- a/ext/standard/dir.c +++ b/ext/standard/dir.c @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2008 The PHP Group | + | Copyright (c) 1997-2009 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: dir.c,v 1.147.2.3.2.16 2008/03/05 12:10:18 tony2001 Exp $ */ +/* $Id: dir.c,v 1.147.2.3.2.21 2008/12/31 11:17:44 sebastian Exp $ */ /* {{{ includes/startup/misc */ @@ -26,6 +26,7 @@ #include "php_dir.h" #include "php_string.h" #include "php_scandir.h" +#include "basic_functions.h" #ifdef HAVE_DIRENT_H #include <dirent.h> @@ -220,6 +221,8 @@ static void _php_do_opendir(INTERNAL_FUNCTION_PARAMETERS, int createobject) if (dirp == NULL) { RETURN_FALSE; } + + dirp->flags |= PHP_STREAM_FLAG_NO_FCLOSE; php_set_default_dir(dirp->rsrc_id TSRMLS_CC); @@ -260,6 +263,11 @@ PHP_FUNCTION(closedir) FETCH_DIRP(); + if (!(dirp->flags & PHP_STREAM_FLAG_IS_DIR)) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "%d is not a valid Directory resource", dirp->rsrc_id); + RETURN_FALSE; + } + rsrc_id = dirp->rsrc_id; zend_list_delete(dirp->rsrc_id); @@ -287,7 +295,7 @@ PHP_FUNCTION(chroot) RETURN_FALSE; } - realpath_cache_clean(TSRMLS_C); + php_clear_stat_cache(TSRMLS_C); ret = chdir("/"); @@ -322,6 +330,15 @@ PHP_FUNCTION(chdir) RETURN_FALSE; } + if (BG(CurrentStatFile) && !IS_ABSOLUTE_PATH(BG(CurrentStatFile), strlen(BG(CurrentStatFile)))) { + efree(BG(CurrentStatFile)); + BG(CurrentStatFile) = NULL; + } + if (BG(CurrentLStatFile) && !IS_ABSOLUTE_PATH(BG(CurrentLStatFile), strlen(BG(CurrentLStatFile)))) { + efree(BG(CurrentLStatFile)); + BG(CurrentLStatFile) = NULL; + } + RETURN_TRUE; } /* }}} */ @@ -360,6 +377,11 @@ PHP_FUNCTION(rewinddir) FETCH_DIRP(); + if (!(dirp->flags & PHP_STREAM_FLAG_IS_DIR)) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "%d is not a valid Directory resource", dirp->rsrc_id); + RETURN_FALSE; + } + php_stream_rewinddir(dirp); } /* }}} */ @@ -374,6 +396,11 @@ PHP_NAMED_FUNCTION(php_if_readdir) FETCH_DIRP(); + if (!(dirp->flags & PHP_STREAM_FLAG_IS_DIR)) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "%d is not a valid Directory resource", dirp->rsrc_id); + RETURN_FALSE; + } + if (php_stream_readdir(dirp, &entry)) { RETURN_STRINGL(entry.d_name, strlen(entry.d_name), 1); } |
