Skip to content

Commit 2f715ee

Browse files
committed
src: validate stdio entries in process_wrap
1 parent 2ebe496 commit 2f715ee

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

src/process_wrap.cc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,12 @@ class ProcessWrap : public HandleWrap {
140140
if (!stdios->Get(context, i).ToLocal(&val)) {
141141
return Nothing<void>();
142142
}
143+
if (!val->IsObject()) {
144+
THROW_ERR_INVALID_ARG_TYPE(env,
145+
"options.stdio[%u] must be an object",
146+
i);
147+
return Nothing<void>();
148+
}
143149
Local<Object> stdio = val.As<Object>();
144150
Local<Value> type;
145151
if (!stdio->Get(context, env->type_string()).ToLocal(&type)) {
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
'use strict';
2+
require('../common');
3+
4+
const assert = require('assert');
5+
const { spawnSyncAndAssert } = require('../common/child_process');
6+
7+
const script = `
8+
Object.defineProperty(Array.prototype, '2', {
9+
__proto__: null,
10+
set() {},
11+
configurable: true,
12+
});
13+
14+
try {
15+
require('child_process').spawn(process.execPath, ['-e', '0']);
16+
console.log('NO_ERROR');
17+
} catch (error) {
18+
console.log(error.code);
19+
}
20+
`;
21+
22+
spawnSyncAndAssert(process.execPath, ['-e', script], {
23+
stdout: (output) => {
24+
assert.match(output, /^ERR_INVALID_ARG_TYPE\\r?\\n$/);
25+
},
26+
stderr: (output) => {
27+
assert.doesNotMatch(output, /FATAL ERROR: v8::ToLocalChecked Empty MaybeLocal/);
28+
},
29+
});

0 commit comments

Comments
 (0)