From: Siddhesh Poyarekar <siddhesh@sourceware.org>
To: libc-stable@sourceware.org
Subject: [COMMITTED 2.34] support: Also return fd when it is 0
Date: Wed, 6 Oct 2021 22:27:25 +0530 [thread overview]
Message-ID: <20211006165725.88556-1-siddhesh@sourceware.org> (raw)
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 <siddhesh@sourceware.org>
Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
(cherry picked from commit 27b6edbb090f736b101f569620d8ad0e7217ddf8)
---
support/support-open-dev-null-range.c | 14 +++++++-------
1 file changed, 7 insertions(+), 7 deletions(-)
diff --git a/support/support-open-dev-null-range.c b/support/support-open-dev-null-range.c
index 80d9dba504..66a8504105 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
--
2.31.1
reply other threads:[~2021-10-06 16:57 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20211006165725.88556-1-siddhesh@sourceware.org \
--to=siddhesh@sourceware.org \
--cc=libc-stable@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).