diff options
author | cjihrig <cjihrig@gmail.com> | 2016-08-28 19:35:13 +0300 |
---|---|---|
committer | cjihrig <cjihrig@gmail.com> | 2016-12-25 20:46:27 +0300 |
commit | b374ee8c3dfcefe7b22060c1a2073ee07e4e1b8c (patch) | |
tree | fc0b76c66d2c940a3c4217ff47e8623aef712861 /src/spawn_sync.cc | |
parent | c65d55f0878a42c5a9fe775ee190d6092c527661 (diff) |
src: add handle check to spawn_sync
This commit verifies that the child process handle is of the
correct type before trying to close it in
CloseHandlesAndDeleteLoop(). This catches the case where input
validation failed, and the child process was never actually
spawned.
Fixes: https://github.com/nodejs/node/issues/8096
Fixes: https://github.com/nodejs/node/issues/8539
Refs: https://github.com/nodejs/node/issues/9722
PR-URL: https://github.com/nodejs/node/pull/8312
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Diffstat (limited to 'src/spawn_sync.cc')
-rw-r--r-- | src/spawn_sync.cc | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/src/spawn_sync.cc b/src/spawn_sync.cc index 79f10a0ea25..689f605e144 100644 --- a/src/spawn_sync.cc +++ b/src/spawn_sync.cc @@ -501,7 +501,12 @@ void SyncProcessRunner::CloseHandlesAndDeleteLoop() { // Close the process handle when ExitCallback was not called. uv_handle_t* uv_process_handle = reinterpret_cast<uv_handle_t*>(&uv_process_); - if (!uv_is_closing(uv_process_handle)) + + // Close the process handle if it is still open. The handle type also + // needs to be checked because TryInitializeAndRunLoop() won't spawn a + // process if input validation fails. + if (uv_process_handle->type == UV_PROCESS && + !uv_is_closing(uv_process_handle)) uv_close(uv_process_handle, nullptr); // Give closing watchers a chance to finish closing and get their close |