Skip to content

Commit 7a3781b

Browse files
cjihrigitaloacasas
authored andcommitted
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: nodejs#8096 Fixes: nodejs#8539 Refs: nodejs#9722 PR-URL: nodejs#8312 Reviewed-By: Ben Noordhuis <[email protected]>
1 parent cb5220d commit 7a3781b

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/spawn_sync.cc

+6-1
Original file line numberDiff line numberDiff line change
@@ -501,7 +501,12 @@ void SyncProcessRunner::CloseHandlesAndDeleteLoop() {
501501
// Close the process handle when ExitCallback was not called.
502502
uv_handle_t* uv_process_handle =
503503
reinterpret_cast<uv_handle_t*>(&uv_process_);
504-
if (!uv_is_closing(uv_process_handle))
504+
505+
// Close the process handle if it is still open. The handle type also
506+
// needs to be checked because TryInitializeAndRunLoop() won't spawn a
507+
// process if input validation fails.
508+
if (uv_process_handle->type == UV_PROCESS &&
509+
!uv_is_closing(uv_process_handle))
505510
uv_close(uv_process_handle, nullptr);
506511

507512
// Give closing watchers a chance to finish closing and get their close

0 commit comments

Comments
 (0)