diff options
author | Anatol Belski <ab@php.net> | 2018-11-16 23:19:33 +0100 |
---|---|---|
committer | Anatol Belski <ab@php.net> | 2018-11-16 23:19:33 +0100 |
commit | a7e9790969952c0574d8708277abfd25d12f58e5 (patch) | |
tree | 076af5ec7afbcdfb6f93d4ca6d9511a1a9c12931 | |
parent | 211c6189f6921c17ec55a3b422ab5fa4bdd5e88f (diff) | |
download | php-git-a7e9790969952c0574d8708277abfd25d12f58e5.tar.gz |
Fixed bug #77111 php-win.exe corrupts unicode symbols from cli parameters
The binary can be of course used on console, for whatever reasons, so
UNICODE API should be used in that case. That might however not work as
expected, if the binary is used for a service.
-rw-r--r-- | sapi/cli/config.w32 | 1 | ||||
-rw-r--r-- | sapi/cli/php_cli.c | 9 | ||||
-rw-r--r-- | sapi/cli/tests/argv_mb_bug77111.phpt | 42 |
3 files changed, 47 insertions, 5 deletions
diff --git a/sapi/cli/config.w32 b/sapi/cli/config.w32 index c510e231d1..2b54f7dee1 100644 --- a/sapi/cli/config.w32 +++ b/sapi/cli/config.w32 @@ -23,4 +23,5 @@ if (PHP_CLI == "yes") { if (PHP_CLI_WIN32 == "yes") { SAPI('cli_win32', 'cli_win32.c php_cli_process_title.c ps_title.c', 'php-win.exe', '/DZEND_ENABLE_STATIC_TSRMLS_CACHE=1'); ADD_FLAG("LDFLAGS_CLI_WIN32", "/stack:67108864"); + ADD_FLAG("LIBS_CLI_WIN32", "shell32.lib"); } diff --git a/sapi/cli/php_cli.c b/sapi/cli/php_cli.c index b217b2731d..86d2c6d224 100644 --- a/sapi/cli/php_cli.c +++ b/sapi/cli/php_cli.c @@ -651,7 +651,7 @@ static int cli_seek_file_begin(zend_file_handle *file_handle, char *script_file, /* }}} */ /*{{{ php_cli_win32_ctrl_handler */ -#if defined(PHP_WIN32) && !defined(PHP_CLI_WIN32_NO_CONSOLE) +#if defined(PHP_WIN32) BOOL WINAPI php_cli_win32_ctrl_handler(DWORD sig) { (void)php_win32_cp_cli_do_restore(orig_cp); @@ -1204,12 +1204,11 @@ int main(int argc, char *argv[]) # ifdef PHP_CLI_WIN32_NO_CONSOLE int argc = __argc; char **argv = __argv; -# else +# endif int num_args; wchar_t **argv_wide; char **argv_save = argv; BOOL using_wide_argv = 0; -# endif #endif int c; @@ -1379,7 +1378,7 @@ exit_loop: } module_started = 1; -#if defined(PHP_WIN32) && !defined(PHP_CLI_WIN32_NO_CONSOLE) +#if defined(PHP_WIN32) php_win32_cp_cli_setup(); orig_cp = (php_win32_cp_get_orig())->id; /* Ignore the delivered argv and argc, read from W API. This place @@ -1425,7 +1424,7 @@ out: tsrm_shutdown(); #endif -#if defined(PHP_WIN32) && !defined(PHP_CLI_WIN32_NO_CONSOLE) +#if defined(PHP_WIN32) (void)php_win32_cp_cli_restore(); if (using_wide_argv) { diff --git a/sapi/cli/tests/argv_mb_bug77111.phpt b/sapi/cli/tests/argv_mb_bug77111.phpt new file mode 100644 index 0000000000..e21cc07678 --- /dev/null +++ b/sapi/cli/tests/argv_mb_bug77111.phpt @@ -0,0 +1,42 @@ +--TEST-- +Bug #77111 php-win.exe corrupts unicode symbols from cli parameters +--SKIPIF-- +<?php +include "skipif.inc"; + +if (strtoupper(substr(PHP_OS, 0, 3)) !== 'WIN') { + die("skip this test is for Windows platforms only"); +} + +$php = dirname(getenv('TEST_PHP_EXECUTABLE')) . DIRECTORY_SEPARATOR . "php-win.exe"; +if (!file_exists($php)) { + die("skip php-win.exe doesn't exist"); +} + +?> +--FILE-- +<?php + +$php = dirname(getenv('TEST_PHP_EXECUTABLE')) . DIRECTORY_SEPARATOR . "php-win.exe"; + +$out_fl = dirname(__FILE__) . "\\argv_bug77111.txt"; + +$argv_fl = dirname(__FILE__) . DIRECTORY_SEPARATOR . "argv_test.php"; +file_put_contents($argv_fl, "<?php file_put_contents('$out_fl', implode(' ', array_slice(\$argv, 1))); ?>"); + +`$php -n $argv_fl Ästhetik Æstetik Esthétique Estética Эстетика`; +var_dump(file_get_contents($out_fl)); + +?> +==DONE== +--CLEAN-- +<?php +$out_fl = dirname(__FILE__) . "\\argv_bug77111.txt"; +$argv_fl = dirname(__FILE__) . DIRECTORY_SEPARATOR . "argv_test.php"; +unlink($argv_fl); +unlink($out_fl); +?> +--EXPECTF-- +string(57) "Ästhetik Æstetik Esthétique Estética Эстетика" +==DONE== + |