[php-src] PHP-8.6: Fix windows embedded CLI argv overwriting (#24733)

From: Date: Tue, 03 Nov 2026 10:12:13 +0000
Subject: [php-src] PHP-8.6: Fix windows embedded CLI argv overwriting (#24733)
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-143268@lists.php.net to get a copy of this message
Author: Marc (henderkes) Committer: GitHub (web-flow) Pusher: arnaud-lb Date: 2026-11-03T11:12:08+01:00 Commit: https://github.com/php/php-src/commit/5a6116fe34b45f04f728a5708bee0be0cc2fd157 Raw diff: https://github.com/php/php-src/commit/5a6116fe34b45f04f728a5708bee0be0cc2fd157.diff Fix windows embedded CLI argv overwriting (#24733) Changed paths: M sapi/cli/cli.h M sapi/cli/php_cli.c Diff: diff --git a/sapi/cli/cli.h b/sapi/cli/cli.h index 9502a6726fe4..abf41d510a59 100644 --- a/sapi/cli/cli.h +++ b/sapi/cli/cli.h @@ -55,6 +55,7 @@ typedef struct php_cli_server_context { } php_cli_server_context; /* this performs full cli-SAPI boot, loads modules, sets up TSRM and co. */ +/* On Windows, custom argv must use PHP's internal encoding (UTF-8 by default). */ extern PHP_CLI_API int do_php_cli(int argc, char *argv[]); #endif /* CLI_H */ diff --git a/sapi/cli/php_cli.c b/sapi/cli/php_cli.c index 0a6aa82a3bec..985ede04b5bd 100644 --- a/sapi/cli/php_cli.c +++ b/sapi/cli/php_cli.c @@ -1335,12 +1335,16 @@ PHP_CLI_API int do_php_cli(int argc, char *argv[]) #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 - might be too late though, but this is the earliest place ATW - we can access the internal charset information from PHP. */ - argv_wide = CommandLineToArgvW(GetCommandLineW(), &num_args); - PHP_WIN32_CP_W_TO_ANY_ARRAY(argv_wide, num_args, argv, argc) - using_wide_argv = 1; + /* Embedders supply their own arguments, we mustn't replace them with + * the ones by the host process command line. */ + if (argv_save == __argv) { + /* Ignore the delivered argv and argc, read from W API. This place + might be too late though, but this is the earliest place ATW + we can access the internal charset information from PHP. */ + argv_wide = CommandLineToArgvW(GetCommandLineW(), &num_args); + PHP_WIN32_CP_W_TO_ANY_ARRAY(argv_wide, num_args, argv, argc) + using_wide_argv = 1; + } SetConsoleCtrlHandler(php_cli_win32_ctrl_handler, TRUE); #endif

« previous php.cvs (#143268) next »