diff --git a/src/node_child_process.cc b/src/node_child_process.cc index 4d14800986e..3adb0ae025d 100644 --- a/src/node_child_process.cc +++ b/src/node_child_process.cc @@ -47,6 +47,8 @@ extern char **environ; #include /* PATH_MAX */ +#define ARRAY_SIZE(a) (sizeof(a) / sizeof(*(a))) + namespace node { using namespace v8; @@ -168,7 +170,7 @@ Handle ChildProcess::Spawn(const Arguments& args) { // Set the custom file descriptor values (if any) for the child process Local custom_fds_handle = Local::Cast(args[4]); int custom_fds_len = custom_fds_handle->Length(); - for (int i = 0; i < custom_fds_len; i++) { + for (int i = 0; i < custom_fds_len && i < ARRAY_SIZE(custom_fds); i++) { if (custom_fds_handle->Get(i)->IsUndefined()) continue; Local fd = custom_fds_handle->Get(i)->ToInteger(); custom_fds[i] = fd->Value();