git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: "Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
Cc: git@vger.kernel.org, josharian@gmail.com
Subject: Re: [PATCH] config.c: handle error case for fstat() calls
Date: Mon, 19 Dec 2016 10:14:27 -0800	[thread overview]
Message-ID: <xmqqtw9zpz0c.fsf@gitster.mtv.corp.google.com> (raw)
In-Reply-To: <20161219092155.20359-1-pclouds@gmail.com> ("Nguyễn Thái Ngọc Duy"'s message of "Mon, 19 Dec 2016 16:21:55 +0700")

Nguyễn Thái Ngọc Duy  <pclouds@gmail.com> writes:

> Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
> ---
>  Will this fix the problem I'm replying to? I don't know. I found this
>  while checking the code and it should be fixed regardless.

Yeah, from a cursory read, it is a step in the right direction to
check the return value of fstat().  

Shouldn't the error-return path in the second hunk rollback the
lockfile to clean after itself?  The existing "Oh, we cannot chmod
to match the original" check that comes immediately after shares the
same issue, so this is not a new problem, but making an existing one
worse.

>  config.c | 12 ++++++++++--
>  1 file changed, 10 insertions(+), 2 deletions(-)
>
> diff --git a/config.c b/config.c
> index 83fdecb..4973256 100644
> --- a/config.c
> +++ b/config.c
> @@ -2194,7 +2194,12 @@ int git_config_set_multivar_in_file_gently(const char *config_filename,
>  			goto out_free;
>  		}
>  
> -		fstat(in_fd, &st);
> +		if (fstat(in_fd, &st) == -1) {
> +			error_errno(_("fstat on %s failed"), config_filename);
> +			ret = CONFIG_INVALID_FILE;
> +			goto out_free;
> +		}
> +
>  		contents_sz = xsize_t(st.st_size);
>  		contents = xmmap_gently(NULL, contents_sz, PROT_READ,
>  					MAP_PRIVATE, in_fd, 0);
> @@ -2414,7 +2419,10 @@ int git_config_rename_section_in_file(const char *config_filename,
>  		goto unlock_and_out;
>  	}
>  
> -	fstat(fileno(config_file), &st);
> +	if (fstat(fileno(config_file), &st) == -1) {
> +		ret = error_errno(_("fstat on %s failed"), config_filename);
> +		goto out;
> +	}
>  
>  	if (chmod(get_lock_file_path(lock), st.st_mode & 07777) < 0) {
>  		ret = error_errno("chmod on %s failed",

  reply	other threads:[~2016-12-19 18:15 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-12-16 18:41 Segfault in git_config_set_multivar_in_file_gently with direct_io in FUSE filesystem Josh Bleecher Snyder
2016-12-19  9:21 ` [PATCH] config.c: handle error case for fstat() calls Nguyễn Thái Ngọc Duy
2016-12-19 18:14   ` Junio C Hamano [this message]
2016-12-20  9:47     ` Duy Nguyen
2016-12-20  9:48       ` [PATCH 1/2] config.c: rename label unlock_and_out Nguyễn Thái Ngọc Duy
2016-12-20  9:48         ` [PATCH 2/2] config.c: handle lock file in error case in git_config_rename_ Nguyễn Thái Ngọc Duy
2016-12-20 20:09           ` Junio C Hamano

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=xmqqtw9zpz0c.fsf@gitster.mtv.corp.google.com \
    --to=gitster@pobox.com \
    --cc=git@vger.kernel.org \
    --cc=josharian@gmail.com \
    --cc=pclouds@gmail.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).