support: Also return fd when it is 0
Checks
Context |
Check |
Description |
dj/TryBot-32bit |
success
|
Build for i686
|
dj/TryBot-apply_patch |
success
|
Patch applied to master at the time it was sent
|
Commit Message
The fd validity check in open_dev_null checks if fd > 0, which would
lead to a leaked fd if it is == 0.
I also went ahead and adjusted formatting of the file since it was off.
Signed-off-by: Siddhesh Poyarekar <siddhesh@sourceware.org>
---
- I own copyright for my submissions to glibc, so using S-o-b
- This is a trivial fix, so I'll push it if there are no objections.
support/support-open-dev-null-range.c | 14 +++++++-------
1 file changed, 7 insertions(+), 7 deletions(-)
Comments
On 06/10/2021 13:25, Siddhesh Poyarekar via Libc-alpha wrote:
> The fd validity check in open_dev_null checks if fd > 0, which would
> lead to a leaked fd if it is == 0.
>
>
> I also went ahead and adjusted formatting of the file since it was off.
>
> Signed-off-by: Siddhesh Poyarekar <siddhesh@sourceware.org>
LGTM, thanks. Please also backport it to 2.34.
Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
> ---
>
> - I own copyright for my submissions to glibc, so using S-o-b
> - This is a trivial fix, so I'll push it if there are no objections.
>
> 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
>
@@ -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