From: Taylor Blau <me@ttaylorr.com>
To: git@vger.kernel.org
Cc: peff@peff.net, dstolee@microsoft.com, gitster@pobox.com
Subject: [PATCH 3/6] builtin/commit-graph.c: die() with unknown '--object-dir'
Date: Thu, 30 Jan 2020 15:00:54 -0800 [thread overview]
Message-ID: <bff635973073f4c496213e0416483985d7a4d12e.1580424766.git.me@ttaylorr.com> (raw)
In-Reply-To: <cover.1580424766.git.me@ttaylorr.com>
The commit-graph sub-commands 'write', 'verify' both take an
'--object-dir' argument, which is used to specify the location of an
object directory containing commit-graphs.
However, there was no verification that the '--object-dir' argument
was an object directory. In the case of an '--object-dir' argument that
either (1) doesn't exist, or (2) isn't an object directory, 'git
commit-graph ...' would exit silently with status zero.
This can clearly lead to unintended behavior, such as verifying
commit-graphs that aren't in a repository's own object store (or one of
its alternates), or causing a typo to mask a legitimate commit-graph
verification failure.
To remedy this, let's wrap 'find_odb()' with 'find_odb_or_die()' and
cause the above such errors to produce an error and non-zero exit code.
Signed-off-by: Taylor Blau <me@ttaylorr.com>
---
Documentation/git-commit-graph.txt | 5 ++++-
builtin/commit-graph.c | 13 +++++++++++--
2 files changed, 15 insertions(+), 3 deletions(-)
diff --git a/Documentation/git-commit-graph.txt b/Documentation/git-commit-graph.txt
index bcd85c1976..28d1fee505 100644
--- a/Documentation/git-commit-graph.txt
+++ b/Documentation/git-commit-graph.txt
@@ -26,7 +26,10 @@ OPTIONS
file. This parameter exists to specify the location of an alternate
that only has the objects directory, not a full `.git` directory. The
commit-graph file is expected to be in the `<dir>/info` directory and
- the packfiles are expected to be in `<dir>/pack`.
+ the packfiles are expected to be in `<dir>/pack`. If the directory
+ could not be made into an absolute path, or does not match any known
+ object directory, `git commit-graph ...` will exit with non-zero
+ status.
--[no-]progress::
Turn progress on/off explicitly. If neither is specified, progress is
diff --git a/builtin/commit-graph.c b/builtin/commit-graph.c
index 3edac318e8..93ff90d73b 100644
--- a/builtin/commit-graph.c
+++ b/builtin/commit-graph.c
@@ -34,6 +34,15 @@ static struct opts_commit_graph {
int progress;
} opts;
+static struct object_directory *find_odb_or_die(struct repository *r,
+ const char *obj_dir)
+{
+ struct object_directory *odb = find_odb(r, obj_dir);
+ if (!odb)
+ die(_("could not find object directory matching %s"), obj_dir);
+ return odb;
+}
+
static int graph_verify(int argc, const char **argv)
{
struct commit_graph *graph = NULL;
@@ -78,7 +87,7 @@ static int graph_verify(int argc, const char **argv)
graph = load_commit_graph_one_fd_st(fd, &st);
else {
struct object_directory *odb;
- if ((odb = find_odb(the_repository, opts.obj_dir)))
+ if ((odb = find_odb_or_die(the_repository, opts.obj_dir)))
graph = read_commit_graph_one(the_repository, odb);
}
@@ -149,7 +158,7 @@ static int graph_write(int argc, const char **argv)
flags |= COMMIT_GRAPH_WRITE_PROGRESS;
read_replace_refs = 0;
- odb = find_odb(the_repository, opts.obj_dir);
+ odb = find_odb_or_die(the_repository, opts.obj_dir);
if (opts.reachable) {
if (write_commit_graph_reachable(odb->path, flags, &split_opts))
--
2.25.0.dirty
next prev parent reply other threads:[~2020-01-30 23:00 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-01-30 23:00 [PATCH 0/6] commit-graph: use 'struct object_directory *' everywhere Taylor Blau
2020-01-30 23:00 ` [PATCH 1/6] t5318: don't pass non-object directory to '--object-dir' Taylor Blau
2020-01-30 23:00 ` [PATCH 5/6] commit-graph.c: remove path normalization, comparison Taylor Blau
2020-01-30 23:00 ` [PATCH 6/6] commit-graph.h: use odb in 'load_commit_graph_one_fd_st' Taylor Blau
2020-01-30 23:00 ` [PATCH 2/6] commit-graph.h: store object directory in 'struct commit_graph' Taylor Blau
2020-01-31 6:52 ` Martin Ågren
2020-01-31 10:20 ` Jeff King
2020-01-31 19:19 ` Martin Ågren
2020-02-03 4:36 ` Taylor Blau
2020-02-03 8:36 ` Jeff King
2020-01-31 20:49 ` Junio C Hamano
2020-02-03 3:58 ` Taylor Blau
2020-01-30 23:00 ` [PATCH 4/6] commit-graph.h: store an odb in 'struct write_commit_graph_context' Taylor Blau
2020-01-30 23:00 ` Taylor Blau [this message]
2020-01-31 10:30 ` [PATCH 0/6] commit-graph: use 'struct object_directory *' everywhere Jeff King
2020-01-31 13:22 ` Derrick Stolee
2020-02-03 4:38 ` Taylor Blau
2020-02-03 21:17 ` [PATCH v2 0/5] " Taylor Blau
2020-02-03 21:17 ` [PATCH v2 1/5] t5318: don't pass non-object directory to '--object-dir' Taylor Blau
2020-02-03 21:17 ` [PATCH v2 2/5] commit-graph.h: store an odb in 'struct write_commit_graph_context' Taylor Blau
2020-02-04 5:51 ` Taylor Blau
2020-02-04 19:54 ` Junio C Hamano
2020-02-04 21:28 ` Taylor Blau
2020-02-04 21:44 ` Junio C Hamano
2020-02-03 21:18 ` [PATCH v2 3/5] commit-graph.h: store object directory in 'struct commit_graph' Taylor Blau
2020-02-03 21:18 ` [PATCH v2 4/5] commit-graph.c: remove path normalization, comparison Taylor Blau
2020-02-03 21:18 ` [PATCH v2 5/5] commit-graph.h: use odb in 'load_commit_graph_one_fd_st' Taylor Blau
2020-02-05 12:30 ` [PATCH v2 0/5] commit-graph: use 'struct object_directory *' everywhere Jeff King
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=bff635973073f4c496213e0416483985d7a4d12e.1580424766.git.me@ttaylorr.com \
--to=me@ttaylorr.com \
--cc=dstolee@microsoft.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=peff@peff.net \
/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).