From: "Vasil Dimov via GitGitGadget" <gitgitgadget@gmail.com>
To: git@vger.kernel.org
Cc: Vasil Dimov <vd@freebsd.org>, Vasil Dimov <vd@FreeBSD.org>
Subject: [PATCH v2 1/2] range-diff: fix a crash in parsing git-log output
Date: Wed, 15 Apr 2020 20:32:24 +0000 [thread overview]
Message-ID: <2375e34100e571f9c3ce658d28aba6648fba18a6.1586982745.git.gitgitgadget@gmail.com> (raw)
In-Reply-To: <pull.760.v2.git.git.1586982745.gitgitgadget@gmail.com>
From: Vasil Dimov <vd@FreeBSD.org>
`git range-diff` calls `git log` internally and tries to parse its
output. But `git log` output can be customized by the user in their
git config and for certain configurations either an error will be
returned by `git range-diff` or it will crash.
To fix this explicitly set the output format of the internally
executed `git log` with `--pretty=medium`. Because that cancels
`--notes`, add explicitly `--notes` at the end.
Also, make sure we never crash in the same way - trying to dereference
`util` which was never created and has remained NULL. It would happen
if the first line of `git log` output does not begin with 'commit '.
Alternative considered but discarded - somehow disable all git configs
and behave as if no config is present in the internally executed
`git log`, but that does not seem to be possible. GIT_CONFIG_NOSYSTEM
is the closest to it, but even with that we would still read
`.git/config`.
Signed-off-by: Vasil Dimov <vd@FreeBSD.org>
---
range-diff.c | 13 +++++++++++++
t/t3206-range-diff.sh | 10 ++++++++++
2 files changed, 23 insertions(+)
diff --git a/range-diff.c b/range-diff.c
index f745567cf67..5cc920be391 100644
--- a/range-diff.c
+++ b/range-diff.c
@@ -63,6 +63,8 @@ static int read_patches(const char *range, struct string_list *list,
"--output-indicator-old=<",
"--output-indicator-context=#",
"--no-abbrev-commit",
+ "--pretty=medium",
+ "--notes",
NULL);
if (other_arg)
argv_array_pushv(&cp.args, other_arg->argv);
@@ -106,6 +108,17 @@ static int read_patches(const char *range, struct string_list *list,
continue;
}
+ if (!util) {
+ error(_("could not parse first line of `log` output: "
+ "did not start with 'commit ': '%s'"),
+ line);
+ string_list_clear(list, 1);
+ strbuf_release(&buf);
+ strbuf_release(&contents);
+ finish_command(&cp);
+ return -1;
+ }
+
if (starts_with(line, "diff --git")) {
struct patch patch = { 0 };
struct strbuf root = STRBUF_INIT;
diff --git a/t/t3206-range-diff.sh b/t/t3206-range-diff.sh
index bd808f87ed5..e024cff65cb 100755
--- a/t/t3206-range-diff.sh
+++ b/t/t3206-range-diff.sh
@@ -513,6 +513,16 @@ test_expect_success 'range-diff overrides diff.noprefix internally' '
git -c diff.noprefix=true range-diff HEAD^...
'
+test_expect_success 'basic with modified format.pretty with suffix' '
+ git -c format.pretty="format:commit %H%d%n" range-diff \
+ master..topic master..unmodified
+'
+
+test_expect_success 'basic with modified format.pretty without "commit "' '
+ git -c format.pretty="format:%H%n" range-diff \
+ master..topic master..unmodified
+'
+
test_expect_success 'range-diff compares notes by default' '
git notes add -m "topic note" topic &&
git notes add -m "unmodified note" unmodified &&
--
gitgitgadget
next prev parent reply other threads:[~2020-04-15 20:32 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-04-15 14:28 [PATCH 0/2] range-diff: fix a crash in parsing git-log output Vasil Dimov via GitGitGadget
2020-04-15 14:28 ` [PATCH 1/2] " Vasil Dimov via GitGitGadget
2020-04-15 15:31 ` Junio C Hamano
2020-04-15 16:16 ` Vasil Dimov
2020-04-15 16:23 ` Jeff King
2020-04-15 22:02 ` Taylor Blau
2020-04-15 22:29 ` Jeff King
2020-04-15 16:13 ` Taylor Blau
2020-04-15 14:28 ` [PATCH 2/2] range-diff: avoid negative string precision Vasil Dimov via GitGitGadget
2020-04-15 16:20 ` Taylor Blau
2020-04-15 20:19 ` Vasil Dimov
2020-04-15 20:32 ` [PATCH v2 0/2] range-diff: fix a crash in parsing git-log output Vasil Dimov via GitGitGadget
2020-04-15 20:32 ` Vasil Dimov via GitGitGadget [this message]
2020-04-15 20:32 ` [PATCH v2 2/2] range-diff: avoid negative string precision Vasil Dimov via GitGitGadget
2020-04-16 1:07 ` [PATCH v2 0/2] range-diff: fix a crash in parsing git-log output Taylor Blau
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=2375e34100e571f9c3ce658d28aba6648fba18a6.1586982745.git.gitgitgadget@gmail.com \
--to=gitgitgadget@gmail.com \
--cc=git@vger.kernel.org \
--cc=vd@freebsd.org \
/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).