(#3424) Fix potential recursive elevation attempts #3425
Merged
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.
Description Of Changes
Add a guard into Start-ChocolateyProcessAsAdmin to ensure we don't accidentally recurse in the case of calling back into helper commands that themselves call Start-ChocolateyProcessAsAdmin.
I don't like how messy the error is, but it's better than spawning infinite processes, and I'm not clear on how to tidy up the error in this case as the clixml is not correctly consumed by the receiving PowerShell process.
Motivation and Context
This shouldn't recurse like this, if the first elevation fails, retrying it is silly.
Testing
I'd like to add tests for this, but I think all our testing currently runs in an admin context, so there's... not much we can do there.
C:\packages
folder: add-path.1.0.0.zip (rename to.nupkg
)$env:ChocolateyInstall = Get-Location
./choco.exe install add-path -s c:\packages -y --params="'/Path=c:\tools /Scope=Machine'"
On current choco versions, this test will break spectacularly, generating endless powershell.exe instances until the processes are killed.
With this change, we instead get a messy, but reasonable, error that the elevation failed:
Operating Systems Testing
Win10
Change Types Made
Change Checklist
Related Issue
Fixes #3424