From 6eccdf92037f6c8ae7d5e764ce7ad90584b0e784 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20Schl=C3=BCter?= Date: Tue, 21 Aug 2007 22:43:38 +0000 Subject: - Fixed Bug #42364 Crash when using getRealPath with DirectoryIterator --- ext/spl/spl_directory.c | 11 ++++++++++- ext/spl/tests/bug42364.phpt | 26 ++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 ext/spl/tests/bug42364.phpt 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-- + +--FILE-- +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=== -- cgit v1.2.1