git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Jeff King <peff@peff.net>
To: "René Scharfe" <l.s.r@web.de>
Cc: Git List <git@vger.kernel.org>, Junio C Hamano <gitster@pobox.com>
Subject: Re: [PATCH] am: check return value of resolve_refdup before using hash
Date: Mon, 8 May 2017 23:58:07 -0400	[thread overview]
Message-ID: <20170509035807.2q7bzhu7cs4fcqkb@sigill.intra.peff.net> (raw)
In-Reply-To: <f0ca65bf-aaf9-2cd6-1deb-c55c9e7a8fa3@web.de>

On Sat, May 06, 2017 at 07:13:56PM +0200, René Scharfe wrote:

> If resolve_refdup() fails it returns NULL and possibly leaves its hash
> output parameter untouched.  Make sure to use it only if the function
> succeeded, in order to avoid accessing uninitialized memory.
> 
> Signed-off-by: Rene Scharfe <l.s.r@web.de>
> ---
>  builtin/am.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/builtin/am.c b/builtin/am.c
> index a95dd8b4e6..2c52c820aa 100644
> --- a/builtin/am.c
> +++ b/builtin/am.c
> @@ -2156,7 +2156,7 @@ static void am_abort(struct am_state *state)
>  	am_rerere_clear();
>  
>  	curr_branch = resolve_refdup("HEAD", 0, curr_head.hash, NULL);
> -	has_curr_head = !is_null_oid(&curr_head);
> +	has_curr_head = curr_branch && !is_null_oid(&curr_head);
>  	if (!has_curr_head)
>  		hashcpy(curr_head.hash, EMPTY_TREE_SHA1_BIN);

This one looks good to me (and no interesting ripple effects from
handling the error correctly :) ).

-Peff

      reply	other threads:[~2017-05-09  3:58 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-05-06 17:13 [PATCH] am: check return value of resolve_refdup before using hash René Scharfe
2017-05-09  3:58 ` Jeff King [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=20170509035807.2q7bzhu7cs4fcqkb@sigill.intra.peff.net \
    --to=peff@peff.net \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=l.s.r@web.de \
    /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).