Skip to content

Commit e3d8546

Browse files
committed
PR feedback
1 parent 712e45c commit e3d8546

File tree

2 files changed

+8
-20
lines changed

2 files changed

+8
-20
lines changed

src/libraries/Common/src/Interop/Unix/System.Native/Interop.IsMemberOfGroup.cs

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,27 +8,13 @@ internal static partial class Interop
88
{
99
internal static partial class Sys
1010
{
11-
internal static bool IsMemberOfGroup(uint gid)
11+
internal static unsafe bool IsMemberOfGroup(uint gid)
1212
{
1313
if (gid == GetEGid())
1414
{
1515
return true;
1616
}
1717

18-
uint[]? groups = GetGroups();
19-
if (groups == null)
20-
{
21-
return false;
22-
}
23-
24-
return Array.IndexOf(groups, gid) >= 0;
25-
}
26-
27-
[GeneratedDllImport(Libraries.SystemNative, EntryPoint = "SystemNative_GetEGid")]
28-
private static partial uint GetEGid();
29-
30-
private static unsafe uint[]? GetGroups()
31-
{
3218
const int InitialGroupsLength =
3319
#if DEBUG
3420
1;
@@ -47,7 +33,7 @@ internal static bool IsMemberOfGroup(uint gid)
4733
if (rv >= 0)
4834
{
4935
// success
50-
return groups.Slice(0, rv).ToArray();
36+
return groups.Slice(0, rv).IndexOf(gid) >= 0;
5137
}
5238
else if (rv == -1 && Interop.Sys.GetLastError() == Interop.Error.EINVAL)
5339
{
@@ -56,13 +42,16 @@ internal static bool IsMemberOfGroup(uint gid)
5642
}
5743
else
5844
{
59-
// failure
60-
return null;
45+
// failure (unexpected)
46+
return false;
6147
}
6248
}
6349
while (true);
6450
}
6551

52+
[GeneratedDllImport(Libraries.SystemNative, EntryPoint = "SystemNative_GetEGid")]
53+
private static partial uint GetEGid();
54+
6655
[GeneratedDllImport(Libraries.SystemNative, EntryPoint = "SystemNative_GetGroups", SetLastError = true)]
6756
private static unsafe partial int GetGroups(int ngroups, uint* groups);
6857
}

src/libraries/System.Diagnostics.Process/src/System/Diagnostics/Process.Unix.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -782,8 +782,7 @@ private static bool IsExecutable(string fullPath)
782782

783783
if (euid == 0)
784784
{
785-
// We're root.
786-
return true;
785+
return true; // We're root.
787786
}
788787

789788
if (euid == fileinfo.Uid)

0 commit comments

Comments
 (0)