gerardog / gsudo

Sudo for Windows
https://gerardog.github.io/gsudo
MIT License
5.21k stars 139 forks source link

Issue: Error: System.ArgumentException: Illegal character in path #365

Open marticliment opened 3 months ago

marticliment commented 3 months ago

Issue Description

Sometimes, when calling using gsudo, some users complain about crashes for "illegal characters in path". The passied command-line arguments, the error seems erratic and not concisely reproducible.

Original Error trace:

Error: System.ArgumentException: Illegales Zeichen im Pfad.
    bei System.IO.Path.CheckInvalidPathChars(String path, Boolean checkAdditional)
    bei System.IO.Path.IsPathRooted(String path)
    bei System.IO.Path.CombineNoChecks(String path1, String path2)
    bei System.IO.StringResultHandler.CreateObject(SearchData searchData, WIN32_FIND_DATA& findData)
    bei System.IO.FileSystemEnumerableIterator`1.MoveNext()
    bei System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
    bei System.IO.Directory.GetFiles(String path)
    bei gsudo.Rpc.NamedPipeUtils.ExistsNamedPipe(String name)
    bei gsudo.Helpers.ServiceHelper.FindServiceByIntegrity(Nullable`1 clientPid, String user)
    bei gsudo.Helpers.ServiceHelper.<FindAnyServiceFast>d__2.MoveNext()
--- Ende der Stapel�berwachung vom vorhergehenden Ort, an dem die Ausnahme ausgel�st wurde ---
    bei System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
    bei System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
    bei gsudo.Commands.RunCommand.<RunUsingService>d__8.MoveNext()
--- Ende der Stapel�berwachung vom vorhergehenden Ort, an dem die Ausnahme ausgel�st wurde ---
    bei System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
    bei System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
    bei gsudo.Commands.RunCommand.<Execute>d__6.MoveNext()
--- Ende der Stapel�berwachung vom vorhergehenden Ort, an dem die Ausnahme ausgel�st wurde ---
    bei System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
    bei System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
    bei gsudo.Program.<Start>d__1.MoveNext()

Translated error trace:

Error: System.ArgumentException: Illegal character in path.
at System.IO.Path.CheckInvalidPathChars(String path, Boolean checkAdditional)
at System.IO.Path.IsPathRooted(String path)
at System.IO.Path.CombineNoChecks(String path1, String path2)
at System.IO.StringResultHandler.CreateObject(SearchData searchData, WIN32_FIND_DATA& findData)
at System.IO.FileSystemEnumerableIterator`1.MoveNext()
at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
at System.IO.Directory.GetFiles(String path)
at gsudo.Rpc.NamedPipeUtils.ExistsNamedPipe(String name)
at gsudo.Helpers.ServiceHelper.FindServiceByIntegrity(Nullable`1 clientPid, String user)
at gsudo.Helpers.ServiceHelper.<FindAnyServiceFast>d__2.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at gsudo.Commands.RunCommand.<RunUsingService>d__8.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at gsudo.Commands.RunCommand.<Execute>d__6.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at gsudo.Program.<Start>d__1.MoveNext()

Process exit code: 999

Steps to Reproduce

Run gsudo.exe with the following arguments: "C:\Users\Giesen\AppData\Local\Microsoft\WindowsApps\winget.exe" update --id Tyrrrz.LightBulb --exact --source winget --accept-source-agreements --version "2.5.3" --silent --disable-interactivity --accept-package-agreements --force --include-unknown

It should be noted that gsudo was called from the gsudo.exe directly, started as a process using System.Diagnostics.Process .NET class. The filename is C:\complete\path\to\gsudo.exe, and the arguments are the ones stated above. The error traceback was captured from STDERR

Screenshots

This is a screenshot of the error shown to the user in my app, which uses gsudo.exe to automate certain tasks.

![image](https://github.com/gerardog/gsudo/assets/53119851/bbbd19ad-6d97-449d-96f7-c8968d1fbe72)

Context:

SirenGlitch commented 2 months ago

Confirming for a similar reason. Recently started using your UniGetUI, started experiencing the same issue you show above but when launching PowerShell (I have the CommandNotFound PowerToys module which uses WinGet on launch) which lead to it crashing almost immediately. Managed to find a temporary fix: ONLY FIXES USERMODE

Change permissions on %TEMP%\WinGet directory to give your user profile Full Access .

Sadly this seems to only work as long as WinGet doesn't get called inside the gsudo elevated environment, which almost completely defeats the point of the fix but it fixes WinGet for anything non-admin