Skip to content

Commit c79dd9e

Browse files
cjihrigMylesBorins
authored andcommitted
src: CHECK() for argument overflow in Spawn()
This commit adds checks for overflow to args and env in Spawn(). It seems extremely unlikely that either of these values would overflow from a valid use case. Fixes: #15622 PR-URL: #16761 Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
1 parent 3acf156 commit c79dd9e

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

src/process_wrap.cc

+3
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,8 @@ class ProcessWrap : public HandleWrap {
154154
if (!argv_v.IsEmpty() && argv_v->IsArray()) {
155155
Local<Array> js_argv = Local<Array>::Cast(argv_v);
156156
int argc = js_argv->Length();
157+
CHECK_GT(argc + 1, 0); // Check for overflow.
158+
157159
// Heap allocate to detect errors. +1 is for nullptr.
158160
options.args = new char*[argc + 1];
159161
for (int i = 0; i < argc; i++) {
@@ -177,6 +179,7 @@ class ProcessWrap : public HandleWrap {
177179
if (!env_v.IsEmpty() && env_v->IsArray()) {
178180
Local<Array> env_opt = Local<Array>::Cast(env_v);
179181
int envc = env_opt->Length();
182+
CHECK_GT(envc + 1, 0); // Check for overflow.
180183
options.env = new char*[envc + 1]; // Heap allocated to detect errors.
181184
for (int i = 0; i < envc; i++) {
182185
node::Utf8Value pair(env->isolate(), env_opt->Get(i));

0 commit comments

Comments
 (0)