From 1f56978a2822fe228f17d4f9a2f4ba4ed628686f Mon Sep 17 00:00:00 2001 From: Ben Noordhuis Date: Sat, 21 Mar 2026 13:18:13 +0100 Subject: [PATCH] unix: check return value of fcntl call (#5089) The fcntl cannot fail at this point but let's check the return code anyway, just in case. Fixes: https://github.com/libuv/libuv/issues/5080 --- src/unix/process.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/unix/process.c b/src/unix/process.c index 9b1fb6929..bbe4a4f4b 100644 --- a/src/unix/process.c +++ b/src/unix/process.c @@ -292,6 +292,7 @@ static void uv__process_child_init(const uv_process_options_t* options, sigset_t signewset; int close_fd; int use_fd; + int err; int fd; int n; @@ -334,9 +335,9 @@ static void uv__process_child_init(const uv_process_options_t* options, if (pipes[fd][1] == -1) uv__write_errno(error_fd); #ifndef F_DUPFD_CLOEXEC /* POSIX 2008 */ - n = uv__cloexec(pipes[fd][1], 1); - if (n) - uv__write_int(error_fd, n); + err = uv__cloexec(pipes[fd][1], 1); + if (err) + uv__write_int(error_fd, err); #endif } @@ -361,9 +362,9 @@ static void uv__process_child_init(const uv_process_options_t* options, if (fd == use_fd) { if (close_fd == -1) { - n = uv__cloexec(use_fd, 0); - if (n) - uv__write_int(error_fd, n); + err = uv__cloexec(use_fd, 0); + if (err) + uv__write_int(error_fd, err); } } else { @@ -373,8 +374,11 @@ static void uv__process_child_init(const uv_process_options_t* options, if (fd == -1) uv__write_errno(error_fd); - if (fd <= 2 && close_fd == -1) - uv__nonblock_fcntl(fd, 0); + if (fd <= 2 && close_fd == -1) { + err = uv__nonblock_fcntl(fd, 0); + if (err) + uv__write_int(error_fd, err); + } if (close_fd >= stdio_count) uv__close(close_fd);