From f5db3f1f859427d2b1252f937a45409c5d4eb38b Mon Sep 17 00:00:00 2001 From: Ryan Dahl Date: Sat, 20 Aug 2011 12:38:31 -0700 Subject: [PATCH] Fix #1563. overflow in ChildProcess custom_fd. --- src/node_child_process.cc | 6 ++++++ test/simple/test-child-process-customfd-bounded.js | 8 ++++++++ 2 files changed, 14 insertions(+) create mode 100644 test/simple/test-child-process-customfd-bounded.js diff --git a/src/node_child_process.cc b/src/node_child_process.cc index 4d14800986e2..87b5cfa9141f 100644 --- a/src/node_child_process.cc +++ b/src/node_child_process.cc @@ -167,7 +167,13 @@ Handle ChildProcess::Spawn(const Arguments& args) { if (args[4]->IsArray()) { // 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(); + // Bound by 3. + if (custom_fds_len > 3) { + custom_fds_len = 3; + } + for (int i = 0; i < custom_fds_len; i++) { if (custom_fds_handle->Get(i)->IsUndefined()) continue; Local fd = custom_fds_handle->Get(i)->ToInteger(); diff --git a/test/simple/test-child-process-customfd-bounded.js b/test/simple/test-child-process-customfd-bounded.js new file mode 100644 index 000000000000..93d061b6bb61 --- /dev/null +++ b/test/simple/test-child-process-customfd-bounded.js @@ -0,0 +1,8 @@ +var common = require('../common'); +var bigish = Array(200); + +for (var i = 0, il = bigish.length; i < il; ++i) + bigish[i] = -1; + +common.spawnPwd({ customFds: bigish }); +