Skip to content

Commit b374ee8

Browse files
committed
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: #8096 Fixes: #8539 Refs: #9722 PR-URL: #8312 Reviewed-By: Ben Noordhuis <[email protected]>
1 parent c65d55f commit b374ee8

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)