diff options
author | Johannes Schlüter <johannes@php.net> | 2007-08-21 22:43:38 +0000 |
---|---|---|
committer | Johannes Schlüter <johannes@php.net> | 2007-08-21 22:43:38 +0000 |
commit | 6eccdf92037f6c8ae7d5e764ce7ad90584b0e784 (patch) | |
tree | 5545eb9634b370553ea06bfdc05806b62f24b708 | |
parent | 16b1288ee1c21ca2195a37c72d4d06378584e4f9 (diff) | |
download | php-git-6eccdf92037f6c8ae7d5e764ce7ad90584b0e784.tar.gz |
- Fixed Bug #42364 Crash when using getRealPath with DirectoryIterator
-rwxr-xr-x | ext/spl/spl_directory.c | 11 | ||||
-rw-r--r-- | ext/spl/tests/bug42364.phpt | 26 |
2 files changed, 36 insertions, 1 deletions
diff --git a/ext/spl/spl_directory.c b/ext/spl/spl_directory.c index db8cf2816a..53d3e88340 100755 --- a/ext/spl/spl_directory.c +++ b/ext/spl/spl_directory.c @@ -1020,13 +1020,17 @@ SPL_METHOD(SplFileInfo, getRealPath) php_set_error_handling(EH_THROW, spl_ce_RuntimeException TSRMLS_CC); + if (intern->type == SPL_FS_DIR && !intern->file_name.v && intern->u.dir.entry.d_name[0]) { + spl_filesystem_object_get_file_name(intern TSRMLS_CC); + } + if (intern->file_name_type == IS_UNICODE) { php_stream_path_encode(NULL, &filename, &filename_len, intern->file_name.u, intern->file_name_len, REPORT_ERRORS, FG(default_context)); } else { filename = intern->file_name.s; } - if (VCWD_REALPATH(filename, buff)) { + if (filename && VCWD_REALPATH(filename, buff)) { #ifdef ZTS if (VCWD_ACCESS(buff, F_OK)) { RETVAL_FALSE; @@ -1044,6 +1048,11 @@ SPL_METHOD(SplFileInfo, getRealPath) } else { RETVAL_FALSE; } + + if (intern->file_name_type == IS_UNICODE && filename) { + efree(filename); + } + php_set_error_handling(EH_NORMAL, NULL TSRMLS_CC); } /* }}} */ diff --git a/ext/spl/tests/bug42364.phpt b/ext/spl/tests/bug42364.phpt new file mode 100644 index 0000000000..3ca083e079 --- /dev/null +++ b/ext/spl/tests/bug42364.phpt @@ -0,0 +1,26 @@ +--TEST-- +Bug #42364 (Crash when using getRealPath with DirectoryIterator) +--SKIPIF-- +<?php if (!extension_loaded("spl")) print "skip"; ?> +--FILE-- +<?php +$it = new DirectoryIterator(dirname(__FILE__)); + +$count = 0; + +foreach ($it as $e) { + $count++; + $type = gettype($e->getRealPath()); + if ($type != "string" && $type != "unicode") { + echo $e->getFilename(), " is a ", gettype($e->getRealPath()), "\n"; + } +} + +if ($count > 0) { + echo "Found $count entries!\n"; +} +echo "===DONE===" +?> +--EXPECTF-- +Found %i entries! +===DONE=== |