Skip to content

Commit 22789fd

Browse files
lundibundiaddaleax
authored andcommitted
child_process: fix handling of incorrect uid/gid in spawn
uid/gid must be uint32, which is asserted on a c++ side but wasn't checked on a JS side and therefore resulted in a process crash. Refs: #22570 PR-URL: #22574 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Weijia Wang <starkwang@126.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
1 parent c57ed41 commit 22789fd

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

lib/child_process.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ const {
3838
ERR_INVALID_OPT_VALUE,
3939
ERR_OUT_OF_RANGE
4040
} = require('internal/errors').codes;
41-
const { validateString } = require('internal/validators');
41+
const { validateString, isInt32 } = require('internal/validators');
4242
const child_process = require('internal/child_process');
4343
const {
4444
_validateStdio,
@@ -426,13 +426,13 @@ function normalizeSpawnArguments(file, args, options) {
426426
}
427427

428428
// Validate the uid, if present.
429-
if (options.uid != null && !Number.isInteger(options.uid)) {
430-
throw new ERR_INVALID_ARG_TYPE('options.uid', 'integer', options.uid);
429+
if (options.uid != null && !isInt32(options.uid)) {
430+
throw new ERR_INVALID_ARG_TYPE('options.uid', 'int32', options.uid);
431431
}
432432

433433
// Validate the gid, if present.
434-
if (options.gid != null && !Number.isInteger(options.gid)) {
435-
throw new ERR_INVALID_ARG_TYPE('options.gid', 'integer', options.gid);
434+
if (options.gid != null && !isInt32(options.gid)) {
435+
throw new ERR_INVALID_ARG_TYPE('options.gid', 'int32', options.gid);
436436
}
437437

438438
// Validate the shell, if present.

test/parallel/test-child-process-spawn-typeerror.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ const invalidArgValueError =
3333
common.expectsError({ code: 'ERR_INVALID_ARG_VALUE', type: TypeError }, 14);
3434

3535
const invalidArgTypeError =
36-
common.expectsError({ code: 'ERR_INVALID_ARG_TYPE', type: TypeError }, 10);
36+
common.expectsError({ code: 'ERR_INVALID_ARG_TYPE', type: TypeError }, 12);
3737

3838
assert.throws(function() {
3939
const child = spawn(invalidcmd, 'this is not an array');
@@ -76,6 +76,14 @@ assert.throws(function() {
7676
spawn(cmd, [], 1);
7777
}, invalidArgTypeError);
7878

79+
assert.throws(function() {
80+
spawn(cmd, [], { uid: 2 ** 63 });
81+
}, invalidArgTypeError);
82+
83+
assert.throws(function() {
84+
spawn(cmd, [], { gid: 2 ** 63 });
85+
}, invalidArgTypeError);
86+
7987
// Argument types for combinatorics.
8088
const a = [];
8189
const o = {};

0 commit comments

Comments
 (0)