Skip to content

Commit 4305759

Browse files
jasnelltargos
authored andcommitted
process: passing -1 to setuid/setgid should not abort
Fixes: #32750 Signed-off-by: James M Snell <jasnell@gmail.com> PR-URL: #36786 Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Harshitha K P <harshitha014@gmail.com> Reviewed-By: Anto Aravinth <anto.aravinth.cse@gmail.com>
1 parent f605bc0 commit 4305759

2 files changed

Lines changed: 9 additions & 0 deletions

File tree

‎lib/internal/bootstrap/switches/does_own_process_state.js‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ function wrapPosixCredentialSetters(credentials) {
8080
functionwrapIdSetter(type,method){
8181
returnfunction(id){
8282
validateId(id,'id');
83+
if(typeofid==='number')id|=0;
8384
// Result is 0 on success, 1 if credential is unknown.
8485
constresult=method(id);
8586
if(result===1){

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

Lines changed: 8 additions & 0 deletions
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
constnewgid=process.getgid();
8391
assert.notStrictEqual(newgid,oldgid);
8492

0 commit comments

Comments
 (0)