summaryrefslogtreecommitdiff
path: root/range-diff.c
diff options
context:
space:
mode:
authorVasil Dimov <vd@FreeBSD.org>2020-04-15 20:32:24 (GMT)
committerJunio C Hamano <gitster@pobox.com>2020-04-16 01:32:47 (GMT)
commit8cf51561d1e15e8f5ad907df00884a7596737dcd (patch)
tree6ea3d2a9cc78824f5ed69c8dece47ad2de9728a0 /range-diff.c
parentde49261b050d9cd8ec73842356077bc5b606640f (diff)
downloadgit-8cf51561d1e15e8f5ad907df00884a7596737dcd.zip
git-8cf51561d1e15e8f5ad907df00884a7596737dcd.tar.gz
git-8cf51561d1e15e8f5ad907df00884a7596737dcd.tar.bz2
range-diff: fix a crash in parsing git-log output
`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> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'range-diff.c')
-rw-r--r--range-diff.c13
1 files changed, 13 insertions, 0 deletions
diff --git a/range-diff.c b/range-diff.c
index f745567..5cc920b 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;