git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCHv2] blame: fix memory corruption scrambling revision name in error message
@ 2017-07-24 21:15 SZEDER Gábor
  2017-07-24 21:41 ` Junio C Hamano
  0 siblings, 1 reply; 2+ messages in thread
From: SZEDER Gábor @ 2017-07-24 21:15 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: Jeff Smith, git, SZEDER Gábor

When attempting to blame a non-existing path, git should show an error
message like this:

  $ git blame e83c51633 -- nonexisting-file
  fatal: no such path nonexisting-file in e83c51633

Since the recent commit 835c49f7d (blame: rework methods that
determine 'final' commit, 2017-05-24) the revision name is either
missing or some scrambled characters are shown instead.  The reason is
that the revision name must be duplicated, because it is invalidated
when the pending objects array is cleared in the meantime, but this
commit dropped the duplication.

Restore the duplication of the revision name in the affected functions
(find_single_final() and find_single_initial()).

Signed-off-by: SZEDER Gábor <szeder.dev@gmail.com>
---

Use xstrdup_or_null() in the first hunk.

 blame.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/blame.c b/blame.c
index 91e26e93e..f575e9cbf 100644
--- a/blame.c
+++ b/blame.c
@@ -1663,7 +1663,7 @@ static struct commit *find_single_final(struct rev_info *revs,
 		name = revs->pending.objects[i].name;
 	}
 	if (name_p)
-		*name_p = name;
+		*name_p = xstrdup_or_null(name);
 	return found;
 }
 
@@ -1735,7 +1735,7 @@ static struct commit *find_single_initial(struct rev_info *revs,
 		die("No commit to dig up from?");
 
 	if (name_p)
-		*name_p = name;
+		*name_p = xstrdup(name);
 	return found;
 }
 
@@ -1843,6 +1843,8 @@ void setup_scoreboard(struct blame_scoreboard *sb, const char *path, struct blam
 
 	if (orig)
 		*orig = o;
+
+	free((char *)final_commit_name);
 }
 
 
-- 
2.14.0.rc0.88.ge338f4246


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCHv2] blame: fix memory corruption scrambling revision name in error message
  2017-07-24 21:15 [PATCHv2] blame: fix memory corruption scrambling revision name in error message SZEDER Gábor
@ 2017-07-24 21:41 ` Junio C Hamano
  0 siblings, 0 replies; 2+ messages in thread
From: Junio C Hamano @ 2017-07-24 21:41 UTC (permalink / raw)
  To: SZEDER Gábor; +Cc: Jeff Smith, git

SZEDER Gábor <szeder.dev@gmail.com> writes:

> When attempting to blame a non-existing path, git should show an error
> message like this:
>
>   $ git blame e83c51633 -- nonexisting-file
>   fatal: no such path nonexisting-file in e83c51633
>
> Since the recent commit 835c49f7d (blame: rework methods that
> determine 'final' commit, 2017-05-24) the revision name is either
> missing or some scrambled characters are shown instead.  The reason is
> that the revision name must be duplicated, because it is invalidated
> when the pending objects array is cleared in the meantime, but this
> commit dropped the duplication.
>
> Restore the duplication of the revision name in the affected functions
> (find_single_final() and find_single_initial()).
>
> Signed-off-by: SZEDER Gábor <szeder.dev@gmail.com>
> ---

Thanks.  

I vaguely recall we had the same breakage in the code that was
already fixed long time ago; that's a strange coincidence if the
js/blame-lib topic reintroduced the same bug ;-).

Will queue.

>
> Use xstrdup_or_null() in the first hunk.
>
>  blame.c | 6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/blame.c b/blame.c
> index 91e26e93e..f575e9cbf 100644
> --- a/blame.c
> +++ b/blame.c
> @@ -1663,7 +1663,7 @@ static struct commit *find_single_final(struct rev_info *revs,
>  		name = revs->pending.objects[i].name;
>  	}
>  	if (name_p)
> -		*name_p = name;
> +		*name_p = xstrdup_or_null(name);
>  	return found;
>  }
>  
> @@ -1735,7 +1735,7 @@ static struct commit *find_single_initial(struct rev_info *revs,
>  		die("No commit to dig up from?");
>  
>  	if (name_p)
> -		*name_p = name;
> +		*name_p = xstrdup(name);
>  	return found;
>  }
>  
> @@ -1843,6 +1843,8 @@ void setup_scoreboard(struct blame_scoreboard *sb, const char *path, struct blam
>  
>  	if (orig)
>  		*orig = o;
> +
> +	free((char *)final_commit_name);
>  }

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2017-07-24 21:41 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-07-24 21:15 [PATCHv2] blame: fix memory corruption scrambling revision name in error message SZEDER Gábor
2017-07-24 21:41 ` Junio C Hamano

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 NNTP newsgroup(s).