-
Notifications
You must be signed in to change notification settings - Fork 8.2k
fix: don't force-overwrite argv if do_php_cli is called by embedder #23891
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
henderkes
wants to merge
3
commits into
php:PHP-8.6
Choose a base branch
from
henderkes:fix/windows-embedded-cli-argv
base: PHP-8.6
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+125
−10
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| test_helpers: $(BUILD_DIR)\php_embed_cli_test.exe | ||
|
|
||
| $(BUILD_DIR)\sapi\embed\cli_argv.obj: $(PHP_SRC_DIR)\sapi\embed\tests\cli_argv.c | ||
| cd $(PHP_SRC_DIR) | ||
| $(CC) $(CFLAGS_EMBED_OBJ) $(CFLAGS) $(CFLAGS_BD_SAPI_EMBED) /Fo$@ /c $(PHP_SRC_DIR)\sapi\embed\tests\cli_argv.c | ||
|
|
||
| $(BUILD_DIR)\php_embed_cli_test.exe: $(BUILD_DIR)\sapi\embed\cli_argv.obj $(BUILD_DIR)\$(EMBED_LIB) | ||
| "$(LINK)" /nologo $(BUILD_DIR)\sapi\embed\cli_argv.obj $(BUILD_DIR)\$(EMBED_LIB) /out:$@ $(LDFLAGS) $(LDFLAGS_EMBED) /stack:67108864 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| #include "php.h" | ||
| #include "sapi/cli/cli.h" | ||
|
|
||
| int main(int argc, char *argv[]) | ||
| { | ||
| char *php_argv[] = { | ||
| "embedded-php", "-n", "-d", "default_charset=UTF-8", "-r", | ||
| "echo json_encode([$argc, array_map('bin2hex', array_slice($argv, 1))]), PHP_EOL; exit(23);", | ||
| "--", "caf\xc3\xa9", "argument with spaces", "", "\xf0\x9f\x98\x80", NULL | ||
| }; | ||
| if (argc > 1 && strcmp(argv[1], "default-charset") == 0) { | ||
| php_argv[3] = "default_charset=Windows-1252"; | ||
| php_argv[10] = "\xe2\x82\xac"; | ||
| } else if (argc > 1 && strcmp(argv[1], "internal-encoding") == 0) { | ||
| php_argv[3] = "internal_encoding=Windows-1252"; | ||
| php_argv[10] = "\xe2\x82\xac"; | ||
| } | ||
| if (argc > 2 && strcmp(argv[2], "file") == 0) { | ||
| php_argv[4] = "-f"; | ||
| php_argv[5] = "cli_argv_caf\xc3\xa9.php"; | ||
| } else if (argc > 2 && strcmp(argv[2], "invalid-utf8") == 0) { | ||
| /* Latin-1 cafe with an accented e, which is not valid UTF-8. */ | ||
| php_argv[7] = "caf\xe9"; | ||
| } | ||
| return do_php_cli((int) (sizeof(php_argv) / sizeof(*php_argv)) - 1, php_argv); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| --TEST-- | ||
| do_php_cli() validates and converts custom UTF-8 argv on Windows | ||
| --SKIPIF-- | ||
| <?php | ||
| if (PHP_OS_FAMILY !== 'Windows') die('skip Windows only'); | ||
| if (!file_exists(dirname(PHP_BINARY) . '/php_embed_cli_test.exe')) { | ||
| die('skip embed SAPI test host is not built (requires --enable-embed)'); | ||
| } | ||
| ?> | ||
| --FILE-- | ||
| <?php | ||
| $host = dirname(PHP_BINARY) . '/php_embed_cli_test.exe'; | ||
| foreach (['ignored-host-argument', 'default-charset', 'internal-encoding'] as $mode) { | ||
| passthru(escapeshellarg($host) . ' ' . $mode, $status); | ||
| var_dump($status); | ||
| passthru(escapeshellarg($host) . ' ' . $mode . ' invalid-utf8 2>&1', $status); | ||
| var_dump($status); | ||
| } | ||
| chdir(__DIR__); | ||
| file_put_contents("cli_argv_caf\xc3\xa9.php", '<?php echo "Unicode filename works\n";'); | ||
| passthru(escapeshellarg($host) . ' default-charset file', $status); | ||
| var_dump($status); | ||
| ?> | ||
| --CLEAN-- | ||
| <?php | ||
| unlink(__DIR__ . "/cli_argv_caf\xc3\xa9.php"); | ||
| ?> | ||
| --EXPECT-- | ||
| [5,["636166c3a9","617267756d656e74207769746820737061636573","","f09f9880"]] | ||
| int(23) | ||
| Invalid UTF-8 in command line argument 7. | ||
| int(1) | ||
| [5,["636166e9","617267756d656e74207769746820737061636573","","80"]] | ||
| int(23) | ||
| Invalid UTF-8 in command line argument 7. | ||
| int(1) | ||
| [5,["636166e9","617267756d656e74207769746820737061636573","","80"]] | ||
| int(23) | ||
| Invalid UTF-8 in command line argument 7. | ||
| int(1) | ||
| Unicode filename works | ||
| int(0) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The caller's own
argvskips the transcoding to PHP's internal charset that theCommandLineToArgvW()branch performs, so a narrowmain()host passingcafé.phpin the ANSI code page hands raw ANSI bytes to the script lookup and to$argv. You may want to document inUPGRADING.INTERNALSthatdo_php_cli()expectsargvin the internal encoding on Windows, or convert fromCP_ACPon this branch.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, fair point. I'm not aware of a safe detection + conversion in winapi, so it might indeed have to be documented.