Skip to content

Commit

Permalink
Fixed cacheable root process algorithm when invoked via Shim #237
Browse files Browse the repository at this point in the history
  • Loading branch information
gerardog committed Mar 2, 2023
1 parent 1f4c272 commit 624c1b3
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/gsudo/Helpers/ProcessHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public static int GetCacheableRootProcessId(this Process process)
int pid = process.Id;
Process p = null;

while (p == null)
while (p == null && pid > 0)
{
pid = GetParentProcessId(pid);
try
Expand All @@ -114,7 +114,8 @@ public static int GetCacheableRootProcessId(this Process process)

if (filename != null && !IsShim(filename))
break;
}
}
p = null;
}

return pid;
Expand Down Expand Up @@ -340,16 +341,21 @@ static internal int GetProcessIntegrityLevel(IntPtr processHandle)
/// <returns></returns>
private static bool IsShim(string fileName)
{
Console.Write($"Is Shim {fileName} ");
try
{
if (!fileName.Equals(ProcessHelper.GetOwnExeName(), StringComparison.OrdinalIgnoreCase)
&& (fileName.EndsWith("\\SUDO.EXE", StringComparison.OrdinalIgnoreCase) ||
fileName.EndsWith("\\GSUDO.EXE", StringComparison.OrdinalIgnoreCase)
))
))
{
Console.WriteLine($"true");
return true;
}
}
catch { } // fails to get parent.MainModule if our parent process is elevated and we are not.

Console.WriteLine($"false");
return false;
}
}
Expand Down

0 comments on commit 624c1b3

Please sign in to comment.