Skip to content

Commit

Permalink
src: add handle check to spawn_sync
Browse files Browse the repository at this point in the history
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: nodejs#8096
Fixes: nodejs#8539
Refs: nodejs#9722
PR-URL: nodejs#8312
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
  • Loading branch information
cjihrig committed Dec 25, 2016
1 parent c65d55f commit b374ee8
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/spawn_sync.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit b374ee8

Please sign in to comment.