Skip to content

Commit 8bda7b8

Browse files
Trottitaloacasas
authored andcommitted
test: add coverage for child_process bounds check
Make sure that monkey-patching process.execArgv doesn't cause child_process to incorrectly munge execArgv in fork(). This basically is adding coverage for an `index > 0` check (see Refs). Previously, that condition was never false in any of the tests. PR-URL: #11800 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com> Reviewed-By: Yuta Hiroto <hello@about-hiroppy.com> Refs: https://github.com/nodejs/node/blob/c67207731f16a78f6cae90e49c53b10728241ecf/lib/child_process.js#L76
1 parent 3ae58ac commit 8bda7b8

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

test/parallel/test-cli-eval.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,17 @@ child.exec(`${nodejs} --use-strict -p process.execArgv`,
122122
assert.strictEqual(stdout, '');
123123
assert.strictEqual(stderr, '');
124124
}));
125+
126+
// Make sure that monkey-patching process.execArgv doesn't cause child_process
127+
// to incorrectly munge execArgv.
128+
child.exec(
129+
`${nodejs} -e "process.execArgv = ['-e', 'console.log(42)', 'thirdArg'];` +
130+
`require('child_process').fork('${emptyFile}')"`,
131+
common.mustCall((err, stdout, stderr) => {
132+
assert.ifError(err);
133+
assert.strictEqual(stdout, '42\n');
134+
assert.strictEqual(stderr, '');
135+
}));
125136
}
126137

127138
// Regression test for https://github.com/nodejs/node/issues/8534.

0 commit comments

Comments
 (0)