Skip to content

Commit a7e9790

Browse files
committed
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.
1 parent 211c618 commit a7e9790

File tree

3 files changed

+47
-5
lines changed

3 files changed

+47
-5
lines changed

sapi/cli/config.w32

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,5 @@ if (PHP_CLI == "yes") {
2323
if (PHP_CLI_WIN32 == "yes") {
2424
SAPI('cli_win32', 'cli_win32.c php_cli_process_title.c ps_title.c', 'php-win.exe', '/DZEND_ENABLE_STATIC_TSRMLS_CACHE=1');
2525
ADD_FLAG("LDFLAGS_CLI_WIN32", "/stack:67108864");
26+
ADD_FLAG("LIBS_CLI_WIN32", "shell32.lib");
2627
}

sapi/cli/php_cli.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -651,7 +651,7 @@ static int cli_seek_file_begin(zend_file_handle *file_handle, char *script_file,
651651
/* }}} */
652652

653653
/*{{{ php_cli_win32_ctrl_handler */
654-
#if defined(PHP_WIN32) && !defined(PHP_CLI_WIN32_NO_CONSOLE)
654+
#if defined(PHP_WIN32)
655655
BOOL WINAPI php_cli_win32_ctrl_handler(DWORD sig)
656656
{
657657
(void)php_win32_cp_cli_do_restore(orig_cp);
@@ -1204,12 +1204,11 @@ int main(int argc, char *argv[])
12041204
# ifdef PHP_CLI_WIN32_NO_CONSOLE
12051205
int argc = __argc;
12061206
char **argv = __argv;
1207-
# else
1207+
# endif
12081208
int num_args;
12091209
wchar_t **argv_wide;
12101210
char **argv_save = argv;
12111211
BOOL using_wide_argv = 0;
1212-
# endif
12131212
#endif
12141213

12151214
int c;
@@ -1379,7 +1378,7 @@ int main(int argc, char *argv[])
13791378
}
13801379
module_started = 1;
13811380

1382-
#if defined(PHP_WIN32) && !defined(PHP_CLI_WIN32_NO_CONSOLE)
1381+
#if defined(PHP_WIN32)
13831382
php_win32_cp_cli_setup();
13841383
orig_cp = (php_win32_cp_get_orig())->id;
13851384
/* Ignore the delivered argv and argc, read from W API. This place
@@ -1425,7 +1424,7 @@ int main(int argc, char *argv[])
14251424
tsrm_shutdown();
14261425
#endif
14271426

1428-
#if defined(PHP_WIN32) && !defined(PHP_CLI_WIN32_NO_CONSOLE)
1427+
#if defined(PHP_WIN32)
14291428
(void)php_win32_cp_cli_restore();
14301429

14311430
if (using_wide_argv) {

sapi/cli/tests/argv_mb_bug77111.phpt

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
--TEST--
2+
Bug #77111 php-win.exe corrupts unicode symbols from cli parameters
3+
--SKIPIF--
4+
<?php
5+
include "skipif.inc";
6+
7+
if (strtoupper(substr(PHP_OS, 0, 3)) !== 'WIN') {
8+
die("skip this test is for Windows platforms only");
9+
}
10+
11+
$php = dirname(getenv('TEST_PHP_EXECUTABLE')) . DIRECTORY_SEPARATOR . "php-win.exe";
12+
if (!file_exists($php)) {
13+
die("skip php-win.exe doesn't exist");
14+
}
15+
16+
?>
17+
--FILE--
18+
<?php
19+
20+
$php = dirname(getenv('TEST_PHP_EXECUTABLE')) . DIRECTORY_SEPARATOR . "php-win.exe";
21+
22+
$out_fl = dirname(__FILE__) . "\\argv_bug77111.txt";
23+
24+
$argv_fl = dirname(__FILE__) . DIRECTORY_SEPARATOR . "argv_test.php";
25+
file_put_contents($argv_fl, "<?php file_put_contents('$out_fl', implode(' ', array_slice(\$argv, 1))); ?>");
26+
27+
`$php -n $argv_fl Ästhetik Æstetik Esthétique Estética Эстетика`;
28+
var_dump(file_get_contents($out_fl));
29+
30+
?>
31+
==DONE==
32+
--CLEAN--
33+
<?php
34+
$out_fl = dirname(__FILE__) . "\\argv_bug77111.txt";
35+
$argv_fl = dirname(__FILE__) . DIRECTORY_SEPARATOR . "argv_test.php";
36+
unlink($argv_fl);
37+
unlink($out_fl);
38+
?>
39+
--EXPECTF--
40+
string(57) "Ästhetik Æstetik Esthétique Estética Эстетика"
41+
==DONE==
42+

0 commit comments

Comments
 (0)