8000 [Process] Windows-style /X flags escaping breaks cmd.exe built-in flag parsing · Issue #58733 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Process] Windows-style /X flags escaping breaks cmd.exe built-in flag parsing #58733

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
Seldaek opened this issue Nov 2, 2024 · 1 comment
Closed

Comments

@Seldaek
Copy link
Member
Seldaek commented Nov 2, 2024

Symfony version(s) affected

5.4+

Description

On windows, some commands like rmdir are built-in commands inside cmd.exe, and not a rmdir.exe process.. And it seems cmd.exe has trouble parsing flags when they are escaped via the env var thing of #21474 (cc @nicolas-grekas).

How to reproduce

<?php

include 'vendor/autoload.php';

mkdir('test/foo/bar', 0777, true);

$p = new Symfony\Component\Process\Process(['rmdir', '/S', '/Q', 'test']);
$p->run();
var_dump($p->getOutput(), $p->getErrorOutput(), $p->getExitCode());

$p = Symfony\Component\Process\Process::fromShellCommandline('rmdir /S /Q test');
$p->run();
var_dump($p->getOutput(), $p->getErrorOutput(), $p->getExitCode());


$p = new Symfony\Component\Process\Process(['ipconfig']);
$p->run();
var_dump($p->getOutput());

$p = new Symfony\Component\Process\Process(['ipconfig', '/all']);
$p->run();
var_dump($p->getOutput()); // correctly shows more info than without /all flag, so this works

Running the above outputs this for the first command using symfony escaping:

string(0) ""
string(117) "The system cannot find the file specified.
The system cannot find the file specified.
The directory is not empty.
"
int(145)

You can see there are 3 errors, because it takes /S, /Q and test as 3 arguments and not two option flags and one argument. So it doesn't find "/S" which indeed is no valid path, same for "/Q", then it finds test but cannot delete it as it is not empty and it requires /S for that to work, but it didn't detect it as an option.

string(0) ""
string(0) ""
int(0)

This second version using a string command works fine.

The ipconfig test works fine in both ways, so I am unsure if the problem is dependent on which command runs, or if it's just cmd.exe built-ins, or what the root cause is.

Possible Solution

I'd say maybe we don't need to escape strings that are just /[a-zA-Z0-9]+, as that seems safe.

Additional Context

Found via composer/composer#12180

@Seldaek
Copy link
Member Author
Seldaek commented Nov 2, 2024

Also tag 9A76 ging @johnstevenson perhaps you have a hint here?

nicolas-grekas added a commit that referenced this issue Nov 4, 2024
…ekas)

This PR was merged into the 5.4 branch.

Discussion
----------

[Process] Fix escaping /X arguments on Windows

| Q             | A
| ------------- | ---
| Branch?       | 5.4
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Issues        | Fix #58733
| License       | MIT

Commits
-------

16902ec [Process] Fix escaping /X arguments on Windows
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants
0