Skip to content

Commit

Permalink
Fixed bug #77111 php-win.exe corrupts unicode symbols from cli parame…
Browse files Browse the repository at this point in the history
…ters

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.
  • Loading branch information
weltling committed Nov 16, 2018
1 parent 211c618 commit a7e9790
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 5 deletions.
1 change: 1 addition & 0 deletions sapi/cli/config.w32
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
9 changes: 4 additions & 5 deletions sapi/cli/php_cli.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -1379,7 +1378,7 @@ int main(int argc, char *argv[])
}
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
Expand Down Expand Up @@ -1425,7 +1424,7 @@ int main(int argc, char *argv[])
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) {
Expand Down
42 changes: 42 additions & 0 deletions sapi/cli/tests/argv_mb_bug77111.phpt
Original file line number Diff line number Diff line change
@@ -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==

0 comments on commit a7e9790

Please sign in to comment.