Skip to content

run-tests.php does not escape path when building cmd #10489

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

Closed
mvorisek opened this issue Feb 2, 2023 · 6 comments · Fixed by #10560
Closed

run-tests.php does not escape path when building cmd #10489

mvorisek opened this issue Feb 2, 2023 · 6 comments · Fixed by #10560

Comments

@mvorisek
Copy link
Contributor

mvorisek commented Feb 2, 2023

Description

https://github.com/php/php-src/blob/php-8.2.2/run-tests.php#L2397

the $php variable is set like: https://github.com/php/php-src/blob/php-8.2.2/run-tests.php#L518

and when it is used to build a full cmd string, it must be escaped, currently when the path contains spaces, the testing fails, especially on Windows, where the path is very often in format like: C:\Program Files\PHP\php.exe

PHP Version

any

Operating System

any

@mvorisek mvorisek changed the title run-tests.php does not escape path run-tests.php does not escape path when building cmd Feb 2, 2023
@nielsdos
Copy link
Member

nielsdos commented Feb 8, 2023

Seems like we can use escapeshellarg to solve this issue I think. But we have to be careful about these lines tho:

$php = $php_cgi . ' -C ';
&
$php = $phpdbg . ' -qIb';
. So we only must do it on the paths, and not blindly on the $php variable.

@nielsdos
Copy link
Member

nielsdos commented Feb 9, 2023

I tried this, and it mostly works. But I ran into the following issue:
Some tests (for example sapi/cli/tests/021.phpt) use a hashbang line to invoke PHP from the CLI. The problem here is that it is not possible to escape a path in the hashbang line, so those tests will fail. The only workaround I found is to use a symlink and then override the TEST_PHP_EXECUTABLE environment variable (& friends) in order to use the symlink. But I'm not so sure if the maintainers will like this solution... Another idea might be to simply skip those problematic tests.

@mvorisek
Copy link
Contributor Author

mvorisek commented Feb 9, 2023

isn't shebang ignored when a script is run like php xxx.php?

@nielsdos
Copy link
Member

nielsdos commented Feb 9, 2023

isn't shebang ignored when a script is run like php xxx.php?

Yes, but I'm pretty sure that test does want to test how the hashbang interacts with PHP.

@mvorisek
Copy link
Contributor Author

mvorisek commented Feb 9, 2023

based on conda/conda#186 we can probably skip the test if TEST_PHP_EXECUTABLE (in https://github.com/php/php-src/blob/master/sapi/cli/tests/021.phpt#L17) contain space

@nielsdos
Copy link
Member

nielsdos commented Feb 9, 2023

Yeah I was thinking that as well, sounds reasonable. I'll try that shortly (currently working on another issue report).

nielsdos added a commit to nielsdos/php-src that referenced this issue Feb 10, 2023
Multiple tests had to be changed to escape the arguments in shell
commands. Some tests are skipped because they behave differently with
spaces in the path versus without. One notable example of this is the
hashbang test which does not work because spaces in hashbangs paths are
not supported in Linux.
nielsdos added a commit to nielsdos/php-src that referenced this issue Feb 10, 2023
Multiple tests had to be changed to escape the arguments in shell
commands. Some tests are skipped because they behave differently with
spaces in the path versus without. One notable example of this is the
hashbang test which does not work because spaces in hashbangs paths are
not supported in Linux.
nielsdos added a commit to nielsdos/php-src that referenced this issue Feb 10, 2023
Multiple tests had to be changed to escape the arguments in shell
commands. Some tests are skipped because they behave differently with
spaces in the path versus without. One notable example of this is the
hashbang test which does not work because spaces in hashbangs paths are
not supported in Linux.
nielsdos added a commit to nielsdos/php-src that referenced this issue Feb 10, 2023
Multiple tests had to be changed to escape the arguments in shell
commands. Some tests are skipped because they behave differently with
spaces in the path versus without. One notable example of this is the
hashbang test which does not work because spaces in hashbangs paths are
not supported in Linux.
nielsdos added a commit to nielsdos/php-src that referenced this issue Feb 10, 2023
Multiple tests had to be changed to escape the arguments in shell
commands. Some tests are skipped because they behave differently with
spaces in the path versus without. One notable example of this is the
hashbang test which does not work because spaces in hashbangs paths are
not supported in Linux.
nielsdos added a commit to nielsdos/php-src that referenced this issue Feb 10, 2023
Multiple tests had to be changed to escape the arguments in shell
commands. Some tests are skipped because they behave differently with
spaces in the path versus without. One notable example of this is the
hashbang test which does not work because spaces in hashbangs paths are
not supported in Linux.
nielsdos added a commit to nielsdos/php-src that referenced this issue Feb 11, 2023
Multiple tests had to be changed to escape the arguments in shell
commands. Some tests are skipped because they behave differently with
spaces in the path versus without. One notable example of this is the
hashbang test which does not work because spaces in hashbangs paths are
not supported in Linux.
nielsdos added a commit to nielsdos/php-src that referenced this issue Feb 13, 2023
Multiple tests had to be changed to escape the arguments in shell
commands. Some tests are skipped because they behave differently with
spaces in the path versus without. One notable example of this is the
hashbang test which does not work because spaces in hashbangs paths are
not supported in Linux.
nielsdos added a commit to nielsdos/php-src that referenced this issue Feb 13, 2023
Multiple tests had to be changed to escape the arguments in shell
commands. Some tests are skipped because they behave differently with
spaces in the path versus without. One notable example of this is the
hashbang test which does not work because spaces in hashbangs paths are
not supported in Linux.
nielsdos added a commit to nielsdos/php-src that referenced this issue Feb 15, 2023
Multiple tests had to be changed to escape the arguments in shell
commands. Some tests are skipped because they behave differently with
spaces in the path versus without. One notable example of this is the
hashbang test which does not work because spaces in hashbangs paths are
not supported in Linux.
nielsdos added a commit to nielsdos/php-src that referenced this issue Feb 15, 2023
Multiple tests had to be changed to escape the arguments in shell
commands. Some tests are skipped because they behave differently with
spaces in the path versus without. One notable example of this is the
hashbang test which does not work because spaces in hashbangs paths are
not supported in Linux.
nielsdos added a commit to nielsdos/php-src that referenced this issue Feb 23, 2023
Multiple tests had to be changed to escape the arguments in shell
commands. Some tests are skipped because they behave differently with
spaces in the path versus without. One notable example of this is the
hashbang test which does not work because spaces in hashbangs paths are
not supported in Linux.
nielsdos added a commit to nielsdos/php-src that referenced this issue Feb 25, 2023
Multiple tests had to be changed to escape the arguments in shell
commands. Some tests are skipped because they behave differently with
spaces in the path versus without. One notable example of this is the
hashbang test which does not work because spaces in hashbangs paths are
not supported in Linux.
Girgias pushed a commit that referenced this issue Feb 25, 2023
…10560)

Multiple tests had to be changed to escape the arguments in shell
commands. Some tests are skipped because they behave differently with
spaces in the path versus without. One notable example of this is the
hashbang test which does not work because spaces in hashbangs paths are
not supported in Linux.

Co-authored-by: Michael Voříšek <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants