Skip to content

Commit 180bb0b

Browse files
lundibunditargos
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 <[email protected]> Reviewed-By: Weijia Wang <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]> Reviewed-By: Trivikram Kamat <[email protected]>
1 parent 041c779 commit 180bb0b

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

lib/child_process.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ const {
3737
ERR_INVALID_OPT_VALUE,
3838
ERR_OUT_OF_RANGE
3939
} = require('internal/errors').codes;
40-
const { validateString } = require('internal/validators');
40+
const { validateString, isInt32 } = require('internal/validators');
4141
const child_process = require('internal/child_process');
4242
const {
4343
_validateStdio,
@@ -425,13 +425,13 @@ function normalizeSpawnArguments(file, args, options) {
425425
}
426426

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

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

437437
// Validate the shell, if present.

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

+9-1
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)