Skip to content
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

Issue: Backslashes at end of command, in Powershell, cause gsudo to silently fail #380

Open
PitchBlackNights opened this issue Oct 7, 2024 · 0 comments

Comments

@PitchBlackNights
Copy link

Issue Description

I was creating a python script that requires elevation, and I just decided to use gsudo to provide the elevation. I noticed that it would succeed when I ran the script directly (python ...) or with gsudo python .... But when I ran it with gsudo !! (after running it directly with python ...), it never actually ran the script.

Steps to Reproduce

  1. Open PowerShell (with gsudoModule imported in your PowerShell profile)
  2. Run a command that accepts a file path as the last argument, and add an extra backslash at the end of your path. (For example: ls .\FOLDER\)
  3. Now run gsudo !! and observe that no command output is show (This is because the command was never actually run)
  4. You can also run the command directly with gsudo (For example: gsudo "ls .\FOLDER\")

Logs

Succesfull Run

gsudo.exe --loglevel All "python .\test.py .\a"
Debug: Invoking Shell: PowerShellCore
Debug: Command Line: --loglevel All "python .\test.py .\a"
Debug: Command to run: "C:\Program Files\PowerShell\7\pwsh.EXE" -NoLogo -NoProfile -Command "python .\test.py .\a"
Debug: Using Console mode TokenSwitch
Debug: Caller PID: 22348
Debug: Connected via Named Pipe ProtectedPrefix\Administrators\gsudo_[REDACTED].
Debug: Creating target process: "C:\Program Files\PowerShell\7\pwsh.EXE" -NoLogo -NoProfile -Command "python .\test.py .\a"
Debug: Process token successfully substituted.
You should see this
['.\\test.py', '.\\a']
Debug: Process exited with code 0

Silently Failed Run

gsudo.exe --loglevel All "python .\test.py .\a\"
Debug: Invoking Shell: PowerShellCore
Debug: Command Line: --loglevel All "python .\test.py .\a\\"
Debug: Command to run: "C:\Program Files\PowerShell\7\pwsh.EXE" -NoLogo -NoProfile -Command "python .\test.py .\a\\\"
Debug: Using Console mode TokenSwitch
Debug: Caller PID: 22348
Debug: Connected via Named Pipe ProtectedPrefix\Administrators\gsudo_[REDACTED].
Debug: Creating target process: "C:\Program Files\PowerShell\7\pwsh.EXE" -NoLogo -NoProfile -Command "python .\test.py .\a\\\"
Debug: Process token successfully substituted.
Debug: Process exited with code 1

Additional Info

Trying to run the actual PowerShell Command that gsudo generates still works.

"C:\Program Files\PowerShell\7\pwsh.EXE" -NoLogo -NoProfile -Command "python .\test.py .\a\\\"
=
C:\\*Program` Files*\\PowerShell\\7\\pwsh.EXE -NoLogo -NoProfile -Command "python .\test.py .\a\\\"

My guess is that when parsing the command, it doesn't correctly escape the ending backslash, and that is causing something to happen internally with backslashes escaping quotation marks that shouldn't be.
It seems that it correctly escapes the backslashes (.\a\ -> .\a\\) when getting the command line arguments (Debug: Command Line: --loglevel All "python .\test.py .\a\\"), but something wrong happens when it converted the command to a PowerShell Command (.\a\\ -> .\a\\\).

Context:

  • Windows version: 23H2 (OS Build: 22631.4249)
  • gsudo version: v2.5.1 (Branch.tags-v2.5.1.Sha.25d89fcac99b25534108804cb843fcbebe05a872)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant