Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
12 changes: 7 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, isUint32 } = require('internal/validators');
const child_process = require('internal/child_process');
const {
_validateStdio,
Expand Down Expand Up @@ -425,13 +425,15 @@ 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 &&
(!Number.isInteger(options.uid) || !isUint32(options.uid))) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the Number.isInteger() check still needed? Also, don't we want int32 checks to match the C++ checks?

Copy link
Copy Markdown
Member Author

@lundibundi lundibundi Aug 29, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It will look kind of strange (especially if it's an object: {} >>> 1 and {} | 0) but I guess it is redundant.

I actually thought maybe it's worth changing them too, though I don't have enough knowledge of the topic. Linux usage and googling tell me that uid/gid must be non-negative, though maybe some of the systems we support actually support negative uid/gid. Therefore I'd also like some input on this.
In the end, I can always change those to isint32 and a topic of changing them to uint checks may be resolved in a separate PR.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After some more googling OpenBSD seem to use -2 as internal "nobody" still.
For now, I'll change it to Int32 and we can discuss this later.

throw new ERR_INVALID_ARG_TYPE('options.uid', 'uint32', 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 &&
(!Number.isInteger(options.gid) || !isUint32(options.gid))) {
throw new ERR_INVALID_ARG_TYPE('options.gid', 'uint32', 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