From: Siddhesh Poyarekar Date: Wed, 6 Oct 2021 16:18:35 +0000 (+0530) Subject: support: Also return fd when it is 0 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=558168c78ea1eb8efb33959c1da9d6b5a997fd7b;p=thirdparty%2Fglibc.git support: Also return fd when it is 0 The fd validity check in open_dev_null checks if fd > 0, which would lead to a leaked fd if it is == 0. Signed-off-by: Siddhesh Poyarekar Reviewed-by: Adhemerval Zanella (cherry picked from commit 27b6edbb090f736b101f569620d8ad0e7217ddf8) --- diff --git a/support/support-open-dev-null-range.c b/support/support-open-dev-null-range.c index 80d9dba5040..66a85041055 100644 --- a/support/support-open-dev-null-range.c +++ b/support/support-open-dev-null-range.c @@ -40,16 +40,16 @@ increase_nofile (void) static int open_dev_null (int flags, mode_t mode) { - int fd = open64 ("/dev/null", flags, mode); - if (fd > 0) - return fd; + int fd = open64 ("/dev/null", flags, mode); + if (fd >= 0) + return fd; - if (fd < 0 && errno != EMFILE) - FAIL_EXIT1 ("open64 (\"/dev/null\", 0x%x, 0%o): %m", flags, mode); + if (fd < 0 && errno != EMFILE) + FAIL_EXIT1 ("open64 (\"/dev/null\", 0x%x, 0%o): %m", flags, mode); - increase_nofile (); + increase_nofile (); - return xopen ("/dev/null", flags, mode); + return xopen ("/dev/null", flags, mode); } struct range