Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

child_process: fix handling of incorrect uid/gid in spawn #22574

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions lib/child_process.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const {
ERR_INVALID_OPT_VALUE,
ERR_OUT_OF_RANGE
} = require('internal/errors').codes;
const { validateString } = require('internal/validators');
const { validateString, isInt32 } = require('internal/validators');
const child_process = require('internal/child_process');
const {
_validateStdio,
Expand Down Expand Up @@ -425,13 +425,13 @@ function normalizeSpawnArguments(file, args, options) {
}

// Validate the uid, if present.
if (options.uid != null && !Number.isInteger(options.uid)) {
throw new ERR_INVALID_ARG_TYPE('options.uid', 'integer', options.uid);
if (options.uid != null && !isInt32(options.uid)) {
throw new ERR_INVALID_ARG_TYPE('options.uid', 'int32', options.uid);
}

// Validate the gid, if present.
if (options.gid != null && !Number.isInteger(options.gid)) {
throw new ERR_INVALID_ARG_TYPE('options.gid', 'integer', options.gid);
if (options.gid != null && !isInt32(options.gid)) {
throw new ERR_INVALID_ARG_TYPE('options.gid', 'int32', options.gid);
}

// Validate the shell, if present.
Expand Down
10 changes: 9 additions & 1 deletion test/parallel/test-child-process-spawn-typeerror.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const invalidArgValueError =
common.expectsError({ code: 'ERR_INVALID_ARG_VALUE', type: TypeError }, 14);

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

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

assert.throws(function() {
spawn(cmd, [], { uid: 2 ** 63 });
}, invalidArgTypeError);

assert.throws(function() {
spawn(cmd, [], { gid: 2 ** 63 });
}, invalidArgTypeError);

// Argument types for combinatorics.
const a = [];
const o = {};
Expand Down