Skip to content

Commit 30ecea9

Browse files
committed
process: passing -1 to setuid/setgid should not abort
Fixes: nodejs#32750 Signed-off-by: James M Snell <[email protected]>
1 parent ceb0dc9 commit 30ecea9

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

lib/internal/bootstrap/switches/does_own_process_state.js

+1
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ function wrapPosixCredentialSetters(credentials) {
8181
return function(id) {
8282
validateId(id, 'id');
8383
// Result is 0 on success, 1 if credential is unknown.
84+
if (typeof id === 'number') id |= 0;
8485
const result = method(id);
8586
if (result === 1) {
8687
throw new ERR_UNKNOWN_CREDENTIAL(type, id);

test/parallel/test-process-uid-gid.js

+8
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,13 @@ assert.throws(() => {
5151
message: 'User identifier does not exist: fhqwhgadshgnsdhjsdbkhsdabkfabkveyb'
5252
});
5353

54+
// Passing -0 shouldn't crash the process
55+
// Refs: https://github.com/nodejs/node/issues/32750
56+
try { process.setuid(-0); } catch {}
57+
try { process.seteuid(-0); } catch {}
58+
try { process.setgid(-0); } catch {}
59+
try { process.setegid(-0); } catch {}
60+
5461
// If we're not running as super user...
5562
if (process.getuid() !== 0) {
5663
// Should not throw.
@@ -79,6 +86,7 @@ try {
7986
}
8087
process.setgid('nogroup');
8188
}
89+
8290
const newgid = process.getgid();
8391
assert.notStrictEqual(newgid, oldgid);
8492

0 commit comments

Comments
 (0)