From 09cdc923c2e70d83891b27906a5ec517875879ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sa=C3=BAl=20Ibarra=20Corretg=C3=A9?= Date: Fri, 10 Apr 2015 12:26:49 +0200 Subject: [PATCH] unix: fix potential bug if dup2 fails in uv_spawn PR-URL: https://github.com/libuv/libuv/pull/309 Reviewed-By: Ben Noordhuis --- src/unix/process.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/unix/process.c b/src/unix/process.c index 4990bbcf..f2a83753 100644 --- a/src/unix/process.c +++ b/src/unix/process.c @@ -319,7 +319,12 @@ static void uv__process_child_init(const uv_process_options_t* options, if (fd == use_fd) uv__cloexec(use_fd, 0); else - dup2(use_fd, fd); + fd = dup2(use_fd, fd); + + if (fd == -1) { + uv__write_int(error_fd, -errno); + _exit(127); + } if (fd <= 2) uv__nonblock(fd, 0);