diff options
author | Jason A. Donenfeld | 2020-03-12 20:52:35 -0600 |
---|---|---|
committer | Jason A. Donenfeld | 2020-03-13 17:48:34 -0600 |
commit | 6a8d6d4b5021af6c90ca0da806691987df449469 (patch) | |
tree | db4984608a96ce279e25c580895d4084d2b1e24f | |
parent | 892ba8c3cc0617d2087a2337d8c6e71524d7b49c (diff) | |
download | cgit-6a8d6d4b5021af6c90ca0da806691987df449469.tar.gz |
global: use proper accessors for maybe_tree
A previous commit changed ->tree to ->maybe_tree throughout, which may
have worked at the time, but wasn't safe, because maybe_tree is loaded
lazily. This manifested itself in crashes when using the "follow" log
feature. The proper fix is to use the correct contextual accessors
everytime we want access to maybe_tree. Thankfully, the commit.cocci
script takes care of creating mostly-correct patches that we could then
fix up, resulting in this commit here.
Fixes: 255b78f ("git: update to v2.18.0")
Reviewed-by: Christian Hesse <mail@eworm.de>
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to '')
-rw-r--r-- | ui-blame.c | 6 | ||||
-rw-r--r-- | ui-blob.c | 17 | ||||
-rw-r--r-- | ui-commit.c | 2 | ||||
-rw-r--r-- | ui-diff.c | 4 | ||||
-rw-r--r-- | ui-log.c | 4 | ||||
-rw-r--r-- | ui-plain.c | 7 | ||||
-rw-r--r-- | ui-tree.c | 8 |
7 files changed, 29 insertions, 19 deletions
@@ -290,8 +290,10 @@ void cgit_print_blame(void) walk_tree_ctx.match_baselen = (path_items.match) ? basedir_len(path_items.match) : -1; - read_tree_recursive(the_repository, commit->maybe_tree, "", 0, 0, - &paths, walk_tree, &walk_tree_ctx); + read_tree_recursive(the_repository, + repo_get_commit_tree(the_repository, commit), + "", 0, 0, + &paths, walk_tree, &walk_tree_ctx); if (!walk_tree_ctx.state) cgit_print_error_page(404, "Not found", "Not found"); else if (walk_tree_ctx.state == 2) @@ -56,8 +56,9 @@ int cgit_ref_path_exists(const char *path, const char *ref, int file_only) goto done; if (oid_object_info(the_repository, &oid, &size) != OBJ_COMMIT) goto done; - read_tree_recursive(the_repository, lookup_commit_reference(the_repository, &oid)->maybe_tree, - "", 0, 0, &paths, walk_tree, &walk_tree_ctx); + read_tree_recursive(the_repository, + repo_get_commit_tree(the_repository, lookup_commit_reference(the_repository, &oid)), + "", 0, 0, &paths, walk_tree, &walk_tree_ctx); done: free(path_items.match); @@ -91,8 +92,10 @@ int cgit_print_file(char *path, const char *head, int file_only) type = oid_object_info(the_repository, &oid, &size); if (type == OBJ_COMMIT) { commit = lookup_commit_reference(the_repository, &oid); - read_tree_recursive(the_repository, commit->maybe_tree, - "", 0, 0, &paths, walk_tree, &walk_tree_ctx); + read_tree_recursive(the_repository, + repo_get_commit_tree(the_repository, commit), + "", 0, 0, &paths, walk_tree, + &walk_tree_ctx); if (!walk_tree_ctx.found_path) return -1; type = oid_object_info(the_repository, &oid, &size); @@ -148,8 +151,10 @@ void cgit_print_blob(const char *hex, char *path, const char *head, int file_onl if ((!hex) && type == OBJ_COMMIT && path) { commit = lookup_commit_reference(the_repository, &oid); - read_tree_recursive(the_repository, commit->maybe_tree, - "", 0, 0, &paths, walk_tree, &walk_tree_ctx); + read_tree_recursive(the_repository, + repo_get_commit_tree(the_repository, commit), + "", 0, 0, &paths, walk_tree, + &walk_tree_ctx); type = oid_object_info(the_repository, &oid, &size); } diff --git a/ui-commit.c b/ui-commit.c index 9a47b54..783211f 100644 --- a/ui-commit.c +++ b/ui-commit.c @@ -78,7 +78,7 @@ void cgit_print_commit(char *hex, const char *prefix) html(")</td></tr>\n"); html("<tr><th>tree</th><td colspan='2' class='sha1'>"); tmp = xstrdup(hex); - cgit_tree_link(oid_to_hex(&commit->maybe_tree->object.oid), NULL, NULL, + cgit_tree_link(oid_to_hex(get_commit_tree_oid(commit)), NULL, NULL, ctx.qry.head, tmp, NULL); if (prefix) { html(" /"); @@ -413,7 +413,7 @@ void cgit_print_diff(const char *new_rev, const char *old_rev, "Bad commit: %s", oid_to_hex(new_rev_oid)); return; } - new_tree_oid = &commit->maybe_tree->object.oid; + new_tree_oid = get_commit_tree_oid(commit); if (old_rev) { if (get_oid(old_rev, old_rev_oid)) { @@ -434,7 +434,7 @@ void cgit_print_diff(const char *new_rev, const char *old_rev, "Bad commit: %s", oid_to_hex(old_rev_oid)); return; } - old_tree_oid = &commit2->maybe_tree->object.oid; + old_tree_oid = get_commit_tree_oid(commit2); } else { old_tree_oid = NULL; } @@ -153,8 +153,8 @@ static int show_commit(struct commit *commit, struct rev_info *revs) rem_lines = 0; revs->diffopt.flags.recursive = 1; - diff_tree_oid(&parent->maybe_tree->object.oid, - &commit->maybe_tree->object.oid, + diff_tree_oid(get_commit_tree_oid(parent), + get_commit_tree_oid(commit), "", &revs->diffopt); diffcore_std(&revs->diffopt); @@ -193,13 +193,14 @@ void cgit_print_plain(void) if (!path_items.match) { path_items.match = ""; walk_tree_ctx.match_baselen = -1; - print_dir(&commit->maybe_tree->object.oid, "", 0, ""); + print_dir(get_commit_tree_oid(commit), "", 0, ""); walk_tree_ctx.match = 2; } else walk_tree_ctx.match_baselen = basedir_len(path_items.match); - read_tree_recursive(the_repository, commit->maybe_tree, - "", 0, 0, &paths, walk_tree, &walk_tree_ctx); + read_tree_recursive(the_repository, + repo_get_commit_tree(the_repository, commit), + "", 0, 0, &paths, walk_tree, &walk_tree_ctx); if (!walk_tree_ctx.match) cgit_print_error_page(404, "Not found", "Not found"); else if (walk_tree_ctx.match == 2) @@ -370,12 +370,14 @@ void cgit_print_tree(const char *rev, char *path) walk_tree_ctx.curr_rev = xstrdup(rev); if (path == NULL) { - ls_tree(&commit->maybe_tree->object.oid, NULL, &walk_tree_ctx); + ls_tree(get_commit_tree_oid(commit), NULL, &walk_tree_ctx); goto cleanup; } - read_tree_recursive(the_repository, commit->maybe_tree, "", 0, 0, - &paths, walk_tree, &walk_tree_ctx); + read_tree_recursive(the_repository, + repo_get_commit_tree(the_repository, commit), + "", 0, 0, + &paths, walk_tree, &walk_tree_ctx); if (walk_tree_ctx.state == 1) ls_tail(); else if (walk_tree_ctx.state == 2) |