From: Junio C Hamano <gitster@pobox.com>
To: Taylor Blau <me@ttaylorr.com>
Cc: git@vger.kernel.org, Johannes.Schindelin@gmx.de
Subject: Re: [PATCH] pack-revindex.c: don't close unopened file descriptors
Date: Fri, 26 Feb 2021 14:41:36 -0800 [thread overview]
Message-ID: <xmqqtupyqwnz.fsf@gitster.g> (raw)
In-Reply-To: <34c017296a7c5fe4a2ea70f8a0b2d8586b34a4dc.1614357030.git.me@ttaylorr.com> (Taylor Blau's message of "Fri, 26 Feb 2021 11:31:02 -0500")
Taylor Blau <me@ttaylorr.com> writes:
> When opening a reverse index, load_revindex_from_disk() jumps to the
> 'cleanup' label in case something goes wrong: the reverse index had the
> wrong size, an unrecognized version, or similar.
>
> It also jumps to this label when the reverse index couldn't be opened in
> the first place, which will cause an error with the unguarded close()
> call in the label.
>
> Guard this call with "if (fd >= 0)" to make sure that we have a valid
> file descriptor to close before attempting to close it.
>
> Reported-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>
> Signed-off-by: Taylor Blau <me@ttaylorr.com>
> ---
> Dscho mentioned this to me privately when reviewing Coverity results for
> -rc0. This one is legitimate, and the fix is easy enough, too.
Thanks, both.
>
> pack-revindex.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/pack-revindex.c b/pack-revindex.c
> index 83fe4de773..4262530449 100644
> --- a/pack-revindex.c
> +++ b/pack-revindex.c
> @@ -253,7 +253,8 @@ static int load_revindex_from_disk(char *revindex_name,
> *data_p = (const uint32_t *)data;
> }
>
> - close(fd);
> + if (fd >= 0)
> + close(fd);
> return ret;
> }
>
> --
> 2.30.0.667.g81c0cbc6fd
prev parent reply other threads:[~2021-02-26 22:42 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-02-26 16:31 [PATCH] pack-revindex.c: don't close unopened file descriptors Taylor Blau
2021-02-26 17:55 ` Jeff King
2021-03-01 22:18 ` Johannes Schindelin
2021-02-26 22:41 ` Junio C Hamano [this message]
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
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=xmqqtupyqwnz.fsf@gitster.g \
--to=gitster@pobox.com \
--cc=Johannes.Schindelin@gmx.de \
--cc=git@vger.kernel.org \
--cc=me@ttaylorr.com \
/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.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
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).