git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* [BUG?] git range-diff -Ix @{1}... segfaults
@ 2021-09-03 18:49 Junio C Hamano
  2021-09-04  7:50 ` René Scharfe
  0 siblings, 1 reply; 3+ messages in thread
From: Junio C Hamano @ 2021-09-03 18:49 UTC (permalink / raw)
  To: git; +Cc: Johannes Schindelin

It does not seem to trigger with an empty range, e.g.

    $ git range-diff -Ix HEAD...
    $ git range-diff -Ix HEAD~...
    -:  ---------- > 1:  0a0bc7d03a scalar: accept -C and -c opt...

but when it needs real comparison, the -I seems to kill the command
quite easily.

THanks.

    

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

* Re: [BUG?] git range-diff -Ix @{1}... segfaults
  2021-09-03 18:49 [BUG?] git range-diff -Ix @{1}... segfaults Junio C Hamano
@ 2021-09-04  7:50 ` René Scharfe
  2021-09-07 20:05   ` Junio C Hamano
  0 siblings, 1 reply; 3+ messages in thread
From: René Scharfe @ 2021-09-04  7:50 UTC (permalink / raw)
  To: Junio C Hamano, git
  Cc: Johannes Schindelin, Ævar Arnfjörð Bjarmason

Am 03.09.21 um 20:49 schrieb Junio C Hamano:
> It does not seem to trigger with an empty range, e.g.
>
>     $ git range-diff -Ix HEAD...
>     $ git range-diff -Ix HEAD~...
>     -:  ---------- > 1:  0a0bc7d03a scalar: accept -C and -c opt...
>
> but when it needs real comparison, the -I seems to kill the command
> quite easily.

Reverting c45dc9cf30 (diff: plug memory leak from regcomp() on
{log,diff} -I, 2021-02-11) fixes the segfault.

diff.c::diff_free() frees the ignore_regex member of a struct
diff_options, but doesn't reset the ignore_regex_nr nor clears the
pointer.  It is called from diff.c::diff_flush().

range-diff.c::output() calls diff.c::diff_flush() in a loop with the
same struct diff_options (via range-diff.c::patch_diff()).

So the second iteration of that loop tries to use the already freed
ignore regexes.  Here's a patch for that:

--- >8 ---
Subject: [PATCH] range-diff: avoid segfault with -I

output() reuses the same struct diff_options for multiple calls of
diff_flush().  Set the option no_free to instruct it to keep the
ignore regexes between calls and release them explicitly at the end.

Signed-off-by: René Scharfe <l.s.r@web.de>
---
Test missing because I couldn't see any effect of -I on range-diff.

 range-diff.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/range-diff.c b/range-diff.c
index e731525e66..cac89a2f4f 100644
--- a/range-diff.c
+++ b/range-diff.c
@@ -482,6 +482,7 @@ static void output(struct string_list *a, struct string_list *b,
 	else
 		diff_setup(&opts);

+	opts.no_free = 1;
 	if (!opts.output_format)
 		opts.output_format = DIFF_FORMAT_PATCH;
 	opts.flags.suppress_diff_headers = 1;
@@ -542,6 +543,8 @@ static void output(struct string_list *a, struct string_list *b,
 	strbuf_release(&buf);
 	strbuf_release(&dashes);
 	strbuf_release(&indent);
+	opts.no_free = 0;
+	diff_free(&opts);
 }

 int show_range_diff(const char *range1, const char *range2,
--
2.33.0


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

* Re: [BUG?] git range-diff -Ix @{1}... segfaults
  2021-09-04  7:50 ` René Scharfe
@ 2021-09-07 20:05   ` Junio C Hamano
  0 siblings, 0 replies; 3+ messages in thread
From: Junio C Hamano @ 2021-09-07 20:05 UTC (permalink / raw)
  To: René Scharfe
  Cc: git, Johannes Schindelin, Ævar Arnfjörð Bjarmason

René Scharfe <l.s.r@web.de> writes:

> range-diff.c::output() calls diff.c::diff_flush() in a loop with the
> same struct diff_options (via range-diff.c::patch_diff()).

Woooo, that's, eh, unexpected.

> So the second iteration of that loop tries to use the already freed
> ignore regexes.  Here's a patch for that:

Thanks.

>
> --- >8 ---
> Subject: [PATCH] range-diff: avoid segfault with -I
>
> output() reuses the same struct diff_options for multiple calls of
> diff_flush().  Set the option no_free to instruct it to keep the
> ignore regexes between calls and release them explicitly at the end.
>
> Signed-off-by: René Scharfe <l.s.r@web.de>
> ---
> Test missing because I couldn't see any effect of -I on range-diff.

I wanted to omit my sign-off when comparing a previous series and
the new series (iow, I expected -I"^Signed-off-by: me" to apply to
the outer diff, not the inner "generation of patches to be compared").


>  range-diff.c | 3 +++
>  1 file changed, 3 insertions(+)
>
> diff --git a/range-diff.c b/range-diff.c
> index e731525e66..cac89a2f4f 100644
> --- a/range-diff.c
> +++ b/range-diff.c
> @@ -482,6 +482,7 @@ static void output(struct string_list *a, struct string_list *b,
>  	else
>  		diff_setup(&opts);
>
> +	opts.no_free = 1;
>  	if (!opts.output_format)
>  		opts.output_format = DIFF_FORMAT_PATCH;
>  	opts.flags.suppress_diff_headers = 1;
> @@ -542,6 +543,8 @@ static void output(struct string_list *a, struct string_list *b,
>  	strbuf_release(&buf);
>  	strbuf_release(&dashes);
>  	strbuf_release(&indent);
> +	opts.no_free = 0;
> +	diff_free(&opts);
>  }
>
>  int show_range_diff(const char *range1, const char *range2,
> --
> 2.33.0

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

end of thread, other threads:[~2021-09-07 20:05 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-03 18:49 [BUG?] git range-diff -Ix @{1}... segfaults Junio C Hamano
2021-09-04  7:50 ` René Scharfe
2021-09-07 20:05   ` Junio C Hamano

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).