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

process: passing -1 to setuid/setgid should not abort #36786

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/internal/bootstrap/switches/does_own_process_state.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ function wrapPosixCredentialSetters(credentials) {
return function(id) {
validateId(id, 'id');
// Result is 0 on success, 1 if credential is unknown.
if (typeof id === 'number') id |= 0;
jasnell marked this conversation as resolved.
Show resolved Hide resolved
const result = method(id);
if (result === 1) {
throw new ERR_UNKNOWN_CREDENTIAL(type, id);
Expand Down
8 changes: 8 additions & 0 deletions test/parallel/test-process-uid-gid.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,13 @@ assert.throws(() => {
message: 'User identifier does not exist: fhqwhgadshgnsdhjsdbkhsdabkfabkveyb'
});

// Passing -0 shouldn't crash the process
// Refs: https://github.com/nodejs/node/issues/32750
try { process.setuid(-0); } catch {}
try { process.seteuid(-0); } catch {}
try { process.setgid(-0); } catch {}
try { process.setegid(-0); } catch {}

// If we're not running as super user...
if (process.getuid() !== 0) {
// Should not throw.
Expand Down Expand Up @@ -79,6 +86,7 @@ try {
}
process.setgid('nogroup');
}

const newgid = process.getgid();
assert.notStrictEqual(newgid, oldgid);

Expand Down