Skip to content
This repository has been archived by the owner on May 4, 2018. It is now read-only.

Commit

Permalink
windows: don't duplicate invalid stdio handles
Browse files Browse the repository at this point in the history
  • Loading branch information
piscisaureus committed Aug 8, 2012
1 parent 00d2f22 commit a1157ce
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/win/process-stdio.c
Expand Up @@ -181,6 +181,20 @@ static int uv__create_stdio_pipe_pair(uv_loop_t* loop, uv_pipe_t* server_pipe,
static int uv__duplicate_handle(uv_loop_t* loop, HANDLE handle, HANDLE* dup) {
HANDLE current_process;


/* _get_osfhandle will sometimes return -2 in case of an error. This seems */
/* to happen when fd <= 2 and the process' corresponding stdio handle is */
/* set to NULL. Unfortunately DuplicateHandle will happily duplicate /*
/* (HANDLE) -2, so this situation goes unnoticed until someone tries to */
/* use the duplicate. Therefore we filter out known-invalid handles here. */
if (handle == INVALID_HANDLE_VALUE ||
handle == NULL ||
handle == (HANDLE) -2) {
*dup = INVALID_HANDLE_VALUE;
uv__set_artificial_error(loop, UV_EBADF);
return -1;
}

current_process = GetCurrentProcess();

if (!DuplicateHandle(current_process,
Expand Down

0 comments on commit a1157ce

Please sign in to comment.