public inbox for git@vger.kernel.org 
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox•com>
To: Thomas Gummerer <t.gummerer@gmail•com>
Cc: Simon Ruderich <simon@ruderich•org>,
	git@vger•kernel.org, Mike Hommey <mh@glandium•org>
Subject: Re: [PATCH v2] blame: fix segfault on untracked files
Date: Mon, 29 Aug 2016 14:17:43 -0700	[thread overview]
Message-ID: <xmqqd1kr8ebs.fsf@gitster.mtv.corp.google.com> (raw)
In-Reply-To: <20160829195019.30876-1-t.gummerer@gmail.com> (Thomas Gummerer's message of "Mon, 29 Aug 2016 20:50:19 +0100")

Thomas Gummerer <t.gummerer@gmail•com> writes:

>> The point of this fix is not that we show the exact error message,
>> but we fail in a controlled manner.  I think
>>
>> test_expect_success 'blame untracked file in empty repo' '
>>                >untracked &&
>>                test_must_fail git blame untracked
>>        '
>>
>> is sufficient.
>
> Yeah, I agree with that.
>
> Thanks for the review!

Thanks for a quick follow-up fix during -rc period.

>>  builtin/blame.c  | 3 ++-
>  t/t8002-blame.sh | 5 +++++
>  2 files changed, 7 insertions(+), 1 deletion(-)
>
> diff --git a/builtin/blame.c b/builtin/blame.c
> index 7ec7823..a5bbf91 100644
> --- a/builtin/blame.c
> +++ b/builtin/blame.c
> @@ -2244,7 +2244,8 @@ static void verify_working_tree_path(struct commit *work_tree, const char *path)
>  	pos = cache_name_pos(path, strlen(path));
>  	if (pos >= 0)
>  		; /* path is in the index */
> -	else if (!strcmp(active_cache[-1 - pos]->name, path))
> +	else if (-1 - pos < active_nr &&
> +		 !strcmp(active_cache[-1 - pos]->name, path))
>  		; /* path is in the index, unmerged */
>  	else
>  		die("no such path '%s' in HEAD", path);
> diff --git a/t/t8002-blame.sh b/t/t8002-blame.sh
> index ff09ace..ab79de9 100755
> --- a/t/t8002-blame.sh
> +++ b/t/t8002-blame.sh
> @@ -6,6 +6,11 @@ test_description='git blame'
>  PROG='git blame -c'
>  . "$TEST_DIRECTORY"/annotate-tests.sh
>  
> +test_expect_success 'blame untracked file in empty repo' '
> +	>untracked &&
> +	test_must_fail git blame untracked
> +'
> +
>  PROG='git blame -c -e'
>  test_expect_success 'blame --show-email' '
>  	check_count \

      reply	other threads:[~2016-08-29 21:17 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-08-27 17:53 Crash when using git blame on untracked file Simon Ruderich
2016-08-27 20:01 ` Thomas Gummerer
2016-08-29 18:27   ` Junio C Hamano
2016-08-29 19:50     ` [PATCH v2] blame: fix segfault on untracked files Thomas Gummerer
2016-08-29 21:17       ` 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

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=xmqqd1kr8ebs.fsf@gitster.mtv.corp.google.com \
    --to=gitster@pobox$(echo .)com \
    --cc=git@vger$(echo .)kernel.org \
    --cc=mh@glandium$(echo .)org \
    --cc=simon@ruderich$(echo .)org \
    --cc=t.gummerer@gmail$(echo .)com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html
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