From 2fc66e15eb194ca1e54cd4df7f54bfdc3c87a3cd Mon Sep 17 00:00:00 2001 From: Simon Ruderich Date: Fri, 21 Jun 2013 22:55:13 +0200 Subject: [PATCH] Improve checks for invalid file descriptors. Just in case a real dup*() or fcntl() doesn't return -1 on error, but something like -2. --- src/coloredstderr.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/coloredstderr.c b/src/coloredstderr.c index 586b024..15581a6 100644 --- a/src/coloredstderr.c +++ b/src/coloredstderr.c @@ -406,7 +406,7 @@ HOOK_FUNC_DEF1(int, dup, int, oldfd) { DLSYM_FUNCTION(real_dup, "dup"); newfd = real_dup(oldfd); - if (newfd != -1) { + if (newfd > -1) { dup_fd(oldfd, newfd); } @@ -417,7 +417,7 @@ HOOK_FUNC_DEF2(int, dup2, int, oldfd, int, newfd) { DLSYM_FUNCTION(real_dup2, "dup2"); newfd = real_dup2(oldfd, newfd); - if (newfd != -1) { + if (newfd > -1) { dup_fd(oldfd, newfd); } @@ -428,7 +428,7 @@ HOOK_FUNC_DEF3(int, dup3, int, oldfd, int, newfd, int, flags) { DLSYM_FUNCTION(real_dup3, "dup3"); newfd = real_dup3(oldfd, newfd, flags); - if (newfd != -1) { + if (newfd > -1) { dup_fd(oldfd, newfd); } @@ -460,7 +460,7 @@ HOOK_FUNC_VAR_DEF2(int, fcntl, int, fd, int, cmd /*, ... */) { va_end(ap); /* We only care about duping fds. */ - if (cmd == F_DUPFD && result != -1) { + if (cmd == F_DUPFD && result > -1) { dup_fd(fd, result); } -- 2.43.2