Repository navigation
Drop inherited supplementary groups when supplementaryGroups is [] - #384
Merged
Merged
Conversation
Setting PlatformOptions.supplementaryGroups to an empty array kept the parent's supplementary groups instead of dropping them: both the fallback-path routing check and the C shims tested `count > 0`, so `[]` was indistinguishable from `nil` and setgroups() was never called. Treat any non-nil value, including `[]`, as a request to call setgroups(), keeping `nil` as "inherit". A non-nil empty array now routes to the fallback (fork/exec or Darwin pre-fork) path, Swift passes a count of -1 for `nil`, and the shims call setgroups(n, sgroups) whenever the count is non-negative, so `[]` results in setgroups(0, NULL). Document the nil (inherit) vs empty array (drop all) vs non-empty array (replace) behavior on `supplementaryGroups`, including that any non-nil value requires the privilege to call setgroups(). Fixes #381
Android has no /usr/bin/true, so testSubprocessPlatformOptionsNilSupplementaryGroupsInherits failed there with executableNotFound. Run /bin/sh -c 'exit 0' instead, which is available on every Unix platform the tests run on.
iCharlesHu
approved these changes
Oct 8, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fixes #381.
Setting
PlatformOptions.supplementaryGroupsto[]kept the parent's supplementary groups instead of dropping them. Both the fallback-path routing check (requiresFallbackSpawnPath) and the C shims testedcount > 0, so[]behaved exactly likenilandsetgroups()was never called.Changes
Any non-
nilvalue, including[], is now a request to callsetgroups(); onlynilinherits.requiresFallbackSpawnPathroutes any non-nilsupplementaryGroupsto the fallback path.-1fornil._subprocess_spawn_preforkand_subprocess_fork_execcallsetgroups(n, sgroups)whenever the count is non-negative, so[]becomessetgroups(0, NULL). The convention is documented inprocess_shims.h.The DocC comment on
supplementaryGroups(Darwin and Unix) now spells out each case:nil: inherit (the default)[]: drop allIt also states that any non-
nilvalue requires the privilege to callsetgroups(), and that groups are applied beforegroupID/userID.Behavior change
A process without root that sets
supplementaryGroups = []used to spawn successfully, because the setting was a silent no-op. It now fails with.spawnFailed/EPERM, as it would for any non-empty list.Tests
SpawnPathTests.testPrivilegeChangesRequireTheFallbackPath: flipped the[]expectation and added anilcase.testSubprocessPlatformOptionsEmptySupplementaryGroupsCallsSetgroups(runs without root):[]fails withEPERM, which provessetgroupsis called. It fails without the fix.testSubprocessPlatformOptionsNilSupplementaryGroupsInherits:nilspawns normally.testSubprocessPlatformOptionsEmptySupplementaryGroupsDropsInherited(root only): withgroupID = Gand[],id -Greports onlyG.Tested locally on macOS without root; the root-only tests were skipped there.