Repository navigation
child_process: normalize fork function arguments #20882
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
Changes from all commits
a0d6b15
7a31575
e1199c2
37d6019
529480e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -59,22 +59,29 @@ function stdioStringToArray(option) { | |||||||
| } | ||||||||
|
|
||||||||
| exports.fork = function fork(modulePath /* , args, options */) { | ||||||||
|
|
||||||||
| // Get options and args arguments. | ||||||||
| var execArgv; | ||||||||
| var options = {}; | ||||||||
| var args = []; | ||||||||
| var pos = 1; | ||||||||
| if (pos < arguments.length && Array.isArray(arguments[pos])) { | ||||||||
| args = arguments[pos++]; | ||||||||
| } | ||||||||
|
|
||||||||
| if (pos < arguments.length && arguments[pos] != null) { | ||||||||
| if (typeof arguments[pos] !== 'object') { | ||||||||
| throw new ERR_INVALID_ARG_VALUE(`arguments[${pos}]`, arguments[pos]); | ||||||||
| } | ||||||||
| var args = arguments[1]; | ||||||||
| var options = arguments[2]; | ||||||||
|
|
||||||||
| if (Array.isArray(args)) { | ||||||||
| args = args.slice(0); | ||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is the slice needed? Please add a test case for it and remove it if there is no need for it.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure. But for consistency I took inspiration from current implementation at - Line 403 in 468ab45
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That is not a strong argument. Please just verify this by adding a test as suggested. |
||||||||
| } else if (options !== undefined && | ||||||||
| (args === undefined || | ||||||||
| args === null || | ||||||||
| typeof args !== 'object') | ||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Adding a throw new ERR_INVALID_ARG_VALUE('arg', 'object', options);for the code you mentioned breaks this line in test -
Should we update this test and add assert.thorws for these cases.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, the test cases would continue to work but the code has to be rewritten further. |
||||||||
| ) { | ||||||||
| args = []; | ||||||||
| } else { | ||||||||
| options = args; | ||||||||
| args = []; | ||||||||
| } | ||||||||
|
|
||||||||
| options = util._extend({}, arguments[pos++]); | ||||||||
| if (options === undefined || options === null) { | ||||||||
| options = {}; | ||||||||
| } else if (typeof options !== 'object') { | ||||||||
| throw new ERR_INVALID_ARG_VALUE('options', 'object', options); | ||||||||
| } | ||||||||
|
|
||||||||
| // Prepare arguments for fork: | ||||||||
|
|
||||||||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Accessing arguments without checking the length can lead to OOB accesses. That is not that bad anymore but that requires quite some work for the compiler and it still slows things down. Therefore this way of doing it is not really good.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
would this be better -
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Likely. Just try to make sure each code path is not hit more than absolutely necessary.