Skip to content

Make command searcher not use wildcard search for execution - #9202

Merged
Aditya Patwardhan (adityapatwardhan) merged 44 commits into
PowerShell:masterfrom
TravisEz13:fix_command_searcher
Apr 2, 2019
Merged

Aditya Patwardhan (adityapatwardhan) merged 44 commits into
PowerShell:masterfrom
TravisEz13:fix_command_searcher

Conversation

@TravisEz13

@TravisEz13 Travis Plunk (TravisEz13) commented Mar 22, 2019 •

Copy link
Copy Markdown
Member

PR Summary

Make command searcher not use wildcard search for execution

PR Context

This is a Defense in Depth fix to prevent people from accidentally running a script.

For example, if a user attempted to run .\[my1].ps1 and there is a 1.ps1 in the same folder. 1.ps1 would be executed instead.
The fix allows tab completion and Get-Command to continue to work with the wildcards ([], ?, and *).

PR Checklist

@TravisEz13 Travis Plunk (TravisEz13) added Breaking-Change breaking change that may affect users CL-Engine Indicates that a PR should be marked as an engine change in the Change Log labels Mar 22, 2019
@iSazonov

Copy link
Copy Markdown
Collaborator

If we want unambiguity, can we follow the practice we use in cmdlets? I mean that if name resolution returns several results, then throw.

/cc Michael Klement (@mklement0)

@TravisEz13

Travis Plunk (TravisEz13) commented Mar 22, 2019 •

Copy link
Copy Markdown
Member Author

Ilya (@iSazonov) That code is already there. End the end, both code paths, use the same code. I doubt anyone actually wants to do execution based on wildcards. It can lead to executing unexpected files and VERY bad results.

@mklement0

Copy link
Copy Markdown
Contributor

Glad to see this is getting fixed; it addresses at least part of #4726, which also asks for the >, >> behavior to be fixed - will this PR address that too (haven't looked)?

@TravisEz13

Copy link
Copy Markdown
Member Author

Michael Klement (@mklement0) The intent was not to fix that issue. As #4726 does not directly affect execution, I would not think that the issue would be considered a Defense in Depth fix and I'd prefer to get this fix in before addressing that issue.

@mklement0

Copy link
Copy Markdown
Contributor

Thanks for clarifying, Travis Plunk (@TravisEz13) (but note that #4726 is about execution as well).

@PoshChan

This comment has been minimized.

@SteveL-MSFT Steve Lee (SteveL-MSFT) left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit comment remaining

Comment thread build.psm1 Outdated
[string]$Title = 'PowerShell Core Tests'
[string]$Title = 'PowerShell Core Tests',
[Parameter(ParameterSetName='Wait', Mandatory=$true,
HelpMessage='Wait for the debugger to attach to powershell before pester starts. Debug builds only!')]

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
HelpMessage='Wait for the debugger to attach to powershell before pester starts. Debug builds only!')]
HelpMessage='Wait for the debugger to attach to PowerShell before Pester starts. Debug builds only!')]

@PoshChan

This comment has been minimized.

@PoshChan

This comment has been minimized.

@PoshChan

This comment has been minimized.

@adityapatwardhan
Aditya Patwardhan (adityapatwardhan) merged commit 5e4b4d1 into PowerShell:master Apr 2, 2019
@TravisEz13
Travis Plunk (TravisEz13) deleted the fix_command_searcher branch April 2, 2019 18:57
@iSazonov

Copy link
Copy Markdown
Collaborator

Should we document the command searcher process in Docs repo?

@TravisEz13

Copy link
Copy Markdown
Member Author

The command searcher itself is an implementation detail. We should document the search order for command execution.

Thatgfsj (Thatgfsj) pushed a commit to Thatgfsj-contribs/PowerShell that referenced this pull request Aug 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Breaking-Change breaking change that may affect users CL-Engine Indicates that a PR should be marked as an engine change in the Change Log Committee-Reviewed PS-Committee has reviewed this and made a decision

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants