From 3069ad8dd1400f19a28230d3028048a27d07ce8d Mon Sep 17 00:00:00 2001 From: Anatol Belski Date: Mon, 14 Aug 2017 00:44:19 +0200 Subject: Fixed bug #75063 --- Zend/zend.c | 4 ++ Zend/zend_virtual_cwd.c | 17 +++-- Zend/zend_virtual_cwd.h | 4 ++ .../file/windows_mb_path/bug75063_cp1251.phpt | 80 +++++++++++++++++++++ .../tests/file/windows_mb_path/bug75063_utf8.phpt | 81 ++++++++++++++++++++++ main/main.c | 14 ++++ 6 files changed, 196 insertions(+), 4 deletions(-) create mode 100644 ext/standard/tests/file/windows_mb_path/bug75063_cp1251.phpt create mode 100644 ext/standard/tests/file/windows_mb_path/bug75063_utf8.phpt diff --git a/Zend/zend.c b/Zend/zend.c index 282ad018db..dbda709198 100644 --- a/Zend/zend.c +++ b/Zend/zend.c @@ -660,6 +660,10 @@ int zend_startup(zend_utility_functions *utility_functions, char **extensions) / extern zend_php_scanner_globals language_scanner_globals; #endif +#ifdef ZEND_WIN32 + php_win32_cp_set_by_id(65001); +#endif + start_memory_manager(); virtual_cwd_startup(); /* Could use shutdown to free the main cwd but it would just slow it down for CGI */ diff --git a/Zend/zend_virtual_cwd.c b/Zend/zend_virtual_cwd.c index c42739a744..2fa12f8180 100644 --- a/Zend/zend_virtual_cwd.c +++ b/Zend/zend_virtual_cwd.c @@ -445,11 +445,15 @@ static void cwd_globals_dtor(virtual_cwd_globals *cwd_g) /* {{{ */ } /* }}} */ -CWD_API void virtual_cwd_startup(void) /* {{{ */ +void virtual_cwd_main_cwd_init(uint8_t reinit) /* {{{ */ { char cwd[MAXPATHLEN]; char *result; + if (reinit) { + free(main_cwd_state.cwd); + } + #ifdef NETWARE result = getcwdpath(cwd, NULL, 1); if(result) @@ -461,10 +465,10 @@ CWD_API void virtual_cwd_startup(void) /* {{{ */ ++c; } } -#else -#ifdef ZEND_WIN32 +#elif defined(ZEND_WIN32) ZeroMemory(&cwd, sizeof(cwd)); -#endif + result = php_win32_ioutil_getcwd(cwd, sizeof(cwd)); +#else result = getcwd(cwd, sizeof(cwd)); #endif if (!result) { @@ -478,7 +482,12 @@ CWD_API void virtual_cwd_startup(void) /* {{{ */ } #endif main_cwd_state.cwd = strdup(cwd); +} +/* }}} */ +CWD_API void virtual_cwd_startup(void) /* {{{ */ +{ + virtual_cwd_main_cwd_init(0); #ifdef ZTS ts_allocate_id(&cwd_globals_id, sizeof(virtual_cwd_globals), (ts_allocate_ctor) cwd_globals_ctor, (ts_allocate_dtor) cwd_globals_dtor); #else diff --git a/Zend/zend_virtual_cwd.h b/Zend/zend_virtual_cwd.h index 9a7a1efc72..36ff44c4d0 100644 --- a/Zend/zend_virtual_cwd.h +++ b/Zend/zend_virtual_cwd.h @@ -251,6 +251,10 @@ CWD_API zend_long realpath_cache_size(void); CWD_API zend_long realpath_cache_max_buckets(void); CWD_API realpath_cache_bucket** realpath_cache_get_buckets(void); +#ifdef CWD_EXPORTS +extern void virtual_cwd_main_cwd_init(uint8_t); +#endif + /* The actual macros to be used in programs using TSRM * If the program defines VIRTUAL_DIR it will use the * virtual_* functions diff --git a/ext/standard/tests/file/windows_mb_path/bug75063_cp1251.phpt b/ext/standard/tests/file/windows_mb_path/bug75063_cp1251.phpt new file mode 100644 index 0000000000..1c890ed53a --- /dev/null +++ b/ext/standard/tests/file/windows_mb_path/bug75063_cp1251.phpt @@ -0,0 +1,80 @@ +--TEST-- +Bug #75063 Many filesystem-related functions do not work with multibyte file names, cp1251 +--SKIPIF-- + +--INI-- +default_charset=cp1251 +--FILE-- + +===DONE=== + +--EXPECTF-- +string(4) "" +bool(true) +string(%d) "%sbug75063-cp1251%e" +string(8) "code.php" +string(8) "test.txt" +string(8) ".txt" +===DONE=== + diff --git a/ext/standard/tests/file/windows_mb_path/bug75063_utf8.phpt b/ext/standard/tests/file/windows_mb_path/bug75063_utf8.phpt new file mode 100644 index 0000000000..b4a59d1afc --- /dev/null +++ b/ext/standard/tests/file/windows_mb_path/bug75063_utf8.phpt @@ -0,0 +1,81 @@ +--TEST-- +Bug #75063 Many filesystem-related functions do not work with multibyte file names, UTF-8 +--SKIPIF-- + +--FILE-- + +===DONE=== +--CLEAN-- + + +--EXPECTF-- +string(8) "тест" +bool(true) +string(%d) "%sbug75063-utf8%eтест" +string(8) "code.php" +string(8) "test.txt" +string(12) "таст.txt" +===DONE=== + diff --git a/main/main.c b/main/main.c index f812b33e66..60b5f620a8 100644 --- a/main/main.c +++ b/main/main.c @@ -2221,6 +2221,20 @@ int php_module_startup(sapi_module_struct *sf, zend_module_entry *additional_mod /* Register Zend ini entries */ zend_register_standard_ini_entries(); +#ifdef ZEND_WIN32 + /* Until the current ini values was setup, the current cp is 65001. + If the actual ini vaues are different, some stuff needs to be updated. + It concerns at least main_cwd_state and there might be more. As we're + still in the startup phase, lets use the chance and reinit the relevant + item according to the current codepage. Still, if ini_set() is used + later on, a more intelligent way to update such stuff is needed. + Startup/shutdown routines could involve touching globals and thus + can't always be used on demand. */ + if (!php_win32_cp_use_unicode()) { + virtual_cwd_main_cwd_init(1); + } +#endif + /* Disable realpath cache if an open_basedir is set */ if (PG(open_basedir) && *PG(open_basedir)) { CWDG(realpath_cache_size_limit) = 0; -- cgit v1.2.1