From 506bd484dcdf7d8c3d1c9a1d41fa71b9c00be14d Mon Sep 17 00:00:00 2001 From: Dmitry Stogov Date: Mon, 25 Jun 2007 08:40:20 +0000 Subject: [PATCH] Better fix for bug #41655 --- ext/standard/dir.c | 18 +++++++++--------- ext/standard/tests/file/bug41655_1.phpt | 2 +- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/ext/standard/dir.c b/ext/standard/dir.c index 4d119bfddb..c6f7348867 100644 --- a/ext/standard/dir.c +++ b/ext/standard/dir.c @@ -397,19 +397,19 @@ PHP_FUNCTION(glob) #endif if (PG(safe_mode) || (PG(open_basedir) && *PG(open_basedir))) { - size_t base_len = php_dirname(pattern, strlen(pattern)); - char pos = pattern[base_len]; - - pattern[base_len] = '\0'; - - if (PG(safe_mode) && (!php_checkuid(pattern, NULL, CHECKUID_CHECK_FILE_AND_DIR))) { + int pattern_len = strlen(pattern); + char *basename = estrndup(pattern, pattern_len); + + php_dirname(basename, pattern_len); + if (PG(safe_mode) && (!php_checkuid(basename, NULL, CHECKUID_CHECK_FILE_AND_DIR))) { + efree(basename); RETURN_FALSE; } - if (php_check_open_basedir(pattern TSRMLS_CC)) { + if (php_check_open_basedir(basename TSRMLS_CC)) { + efree(basename); RETURN_FALSE; } - - pattern[base_len] = pos; + efree(basename); } globbuf.gl_offs = 0; diff --git a/ext/standard/tests/file/bug41655_1.phpt b/ext/standard/tests/file/bug41655_1.phpt index 9b047bcace..9338ebd817 100644 --- a/ext/standard/tests/file/bug41655_1.phpt +++ b/ext/standard/tests/file/bug41655_1.phpt @@ -7,4 +7,4 @@ open_basedir=/tmp $a=glob("./*.jpeg"); ?> --EXPECTF-- -Warning: glob() [%s]: open_basedir restriction in effect. File(.) is not within the allowed path(s): (/tmp) in %s on line %d +Warning: glob(): open_basedir restriction in effect. File(.) is not within the allowed path(s): (/tmp) in %s on line %d -- 2.50.1