diff options
author | Daniel Stenberg <daniel@haxx.se> | 2022-10-12 11:49:44 +0200 |
---|---|---|
committer | Daniel Stenberg <daniel@haxx.se> | 2022-10-12 23:51:15 +0200 |
commit | 0bb2f64905d52a902767fea39bfa0f426a87a53f (patch) | |
tree | d364d5b836ae8342ad7baf3f98ccf0d41ce2e80c /src | |
parent | 0df0aa74bebc2a11fca3a96978109d6e743663e3 (diff) | |
download | curl-0bb2f64905d52a902767fea39bfa0f426a87a53f.tar.gz |
curl/main_checkfds: check the fcntl return code better
fcntl() can (in theory) return a non-zero number for success, so a
better test for error is checking for -1 explicitly.
Follow-up to 41e1b30ea1b77e9ff
Mentioned-by: Dominik Klemba
Closes #9708
Diffstat (limited to 'src')
-rw-r--r-- | src/tool_main.c | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/src/tool_main.c b/src/tool_main.c index 9fe6cf969..434979dea 100644 --- a/src/tool_main.c +++ b/src/tool_main.c @@ -90,13 +90,17 @@ int _CRT_glob = 0; * open before starting to run. Otherwise, the first three network * sockets opened by curl could be used for input sources, downloaded data * or error logs as they will effectively be stdin, stdout and/or stderr. + * + * fcntl's F_GETFD instruction returns -1 if the file descriptor is closed, + * otherwise it returns "the file descriptor flags (which typically can only + * be FD_CLOEXEC, which is not set here). */ static int main_checkfds(void) { int fd[2]; - while(fcntl(STDIN_FILENO, F_GETFD) || - fcntl(STDOUT_FILENO, F_GETFD) || - fcntl(STDERR_FILENO, F_GETFD)) + while((fcntl(STDIN_FILENO, F_GETFD) == -1) || + (fcntl(STDOUT_FILENO, F_GETFD) == -1) || + (fcntl(STDERR_FILENO, F_GETFD) == -1)) if(pipe(fd)) return 1; return 0; |