Skip to content

Commit de1754a

Browse files
committed
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: nodejs#15622 PR-URL: nodejs#16761 Reviewed-By: Gireesh Punathil <[email protected]>
1 parent 90a4390 commit de1754a

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
@@ -185,6 +185,8 @@ class ProcessWrap : public HandleWrap {
185185
if (!argv_v.IsEmpty() && argv_v->IsArray()) {
186186
Local<Array> js_argv = Local<Array>::Cast(argv_v);
187187
int argc = js_argv->Length();
188+
CHECK_GT(argc + 1, 0); // Check for overflow.
189+
188190
// Heap allocate to detect errors. +1 is for nullptr.
189191
options.args = new char*[argc + 1];
190192
for (int i = 0; i < argc; i++) {
@@ -211,6 +213,7 @@ class ProcessWrap : public HandleWrap {
211213
if (!env_v.IsEmpty() && env_v->IsArray()) {
212214
Local<Array> env_opt = Local<Array>::Cast(env_v);
213215
int envc = env_opt->Length();
216+
CHECK_GT(envc + 1, 0); // Check for overflow.
214217
options.env = new char*[envc + 1]; // Heap allocated to detect errors.
215218
for (int i = 0; i < envc; i++) {
216219
node::Utf8Value pair(env->isolate(),

0 commit comments

Comments
 (0)