94084c
commit 558168c78ea1eb8efb33959c1da9d6b5a997fd7b
94084c
Author: Siddhesh Poyarekar <siddhesh@sourceware.org>
94084c
Date:   Wed Oct 6 21:48:35 2021 +0530
94084c
94084c
    support: Also return fd when it is 0
94084c
    
94084c
    The fd validity check in open_dev_null checks if fd > 0, which would
94084c
    lead to a leaked fd if it is == 0.
94084c
    
94084c
    Signed-off-by: Siddhesh Poyarekar <siddhesh@sourceware.org>
94084c
    Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>
94084c
    (cherry picked from commit 27b6edbb090f736b101f569620d8ad0e7217ddf8)
94084c
94084c
diff --git a/support/support-open-dev-null-range.c b/support/support-open-dev-null-range.c
94084c
index 80d9dba50402ce12..66a850410557351b 100644
94084c
--- a/support/support-open-dev-null-range.c
94084c
+++ b/support/support-open-dev-null-range.c
94084c
@@ -40,16 +40,16 @@ increase_nofile (void)
94084c
 static int
94084c
 open_dev_null (int flags, mode_t mode)
94084c
 {
94084c
- int fd = open64 ("/dev/null", flags, mode);
94084c
- if (fd > 0)
94084c
-   return fd;
94084c
+  int fd = open64 ("/dev/null", flags, mode);
94084c
+  if (fd >= 0)
94084c
+    return fd;
94084c
 
94084c
- if (fd < 0 && errno != EMFILE)
94084c
-   FAIL_EXIT1 ("open64 (\"/dev/null\", 0x%x, 0%o): %m", flags, mode);
94084c
+  if (fd < 0 && errno != EMFILE)
94084c
+    FAIL_EXIT1 ("open64 (\"/dev/null\", 0x%x, 0%o): %m", flags, mode);
94084c
 
94084c
- increase_nofile ();
94084c
+  increase_nofile ();
94084c
 
94084c
- return xopen ("/dev/null", flags, mode);
94084c
+  return xopen ("/dev/null", flags, mode);
94084c
 }
94084c
 
94084c
 struct range