Skip to content

Commit 94afc3e

Browse files
jasnelldanielleadams
authored andcommittedJan 12, 2021
process: passing -1 to setuid/setgid should not abort
Fixes: #32750 Signed-off-by: James M Snell <[email protected]> PR-URL: #36786 Reviewed-By: Antoine du Hamel <[email protected]> Reviewed-By: Michaël Zasso <[email protected]> Reviewed-By: Harshitha K P <[email protected]> Reviewed-By: Anto Aravinth <[email protected]>
1 parent 1a4d34e commit 94afc3e

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
@@ -80,6 +80,7 @@ function wrapPosixCredentialSetters(credentials) {
8080
function wrapIdSetter(type, method) {
8181
return function(id) {
8282
validateId(id, 'id');
83+
if (typeof id === 'number') id |= 0;
8384
// Result is 0 on success, 1 if credential is unknown.
8485
const result = method(id);
8586
if (result === 1) {

‎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)
Please sign in to comment.