aboutsummaryrefslogtreecommitdiffstats
path: root/ui-blob.c
diff options
context:
space:
mode:
authorJason A. Donenfeld2020-03-12 20:52:35 -0600
committerJason A. Donenfeld2020-03-13 17:48:34 -0600
commit6a8d6d4b5021af6c90ca0da806691987df449469 (patch)
treedb4984608a96ce279e25c580895d4084d2b1e24f /ui-blob.c
parent892ba8c3cc0617d2087a2337d8c6e71524d7b49c (diff)
downloadcgit-6a8d6d4b5021af6c90ca0da806691987df449469.tar.gz
cgit-6a8d6d4b5021af6c90ca0da806691987df449469.tar.bz2
cgit-6a8d6d4b5021af6c90ca0da806691987df449469.zip
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 'ui-blob.c')
-rw-r--r--ui-blob.c17
1 files changed, 11 insertions, 6 deletions
diff --git a/ui-blob.c b/ui-blob.c
index 30e2d4b..f76c641 100644
--- a/ui-blob.c
+++ b/ui-blob.c
@@ -56,8 +56,9 @@ int cgit_ref_path_exists(const char *path, const char *ref, int file_only)
56 goto done; 56 goto done;
57 if (oid_object_info(the_repository, &oid, &size) != OBJ_COMMIT) 57 if (oid_object_info(the_repository, &oid, &size) != OBJ_COMMIT)
58 goto done; 58 goto done;
59 read_tree_recursive(the_repository, lookup_commit_reference(the_repository, &oid)->maybe_tree, 59 read_tree_recursive(the_repository,
60 "", 0, 0, &paths, walk_tree, &walk_tree_ctx); 60 repo_get_commit_tree(the_repository, lookup_commit_reference(the_repository, &oid)),
61 "", 0, 0, &paths, walk_tree, &walk_tree_ctx);
61 62
62done: 63done:
63 free(path_items.match); 64 free(path_items.match);
@@ -91,8 +92,10 @@ int cgit_print_file(char *path, const char *head, int file_only)
91 type = oid_object_info(the_repository, &oid, &size); 92 type = oid_object_info(the_repository, &oid, &size);
92 if (type == OBJ_COMMIT) { 93 if (type == OBJ_COMMIT) {
93 commit = lookup_commit_reference(the_repository, &oid); 94 commit = lookup_commit_reference(the_repository, &oid);
94 read_tree_recursive(the_repository, commit->maybe_tree, 95 read_tree_recursive(the_repository,
95 "", 0, 0, &paths, walk_tree, &walk_tree_ctx); 96 repo_get_commit_tree(the_repository, commit),
97 "", 0, 0, &paths, walk_tree,
98 &walk_tree_ctx);
96 if (!walk_tree_ctx.found_path) 99 if (!walk_tree_ctx.found_path)
97 return -1; 100 return -1;
98 type = oid_object_info(the_repository, &oid, &size); 101 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
148 151
149 if ((!hex) && type == OBJ_COMMIT && path) { 152 if ((!hex) && type == OBJ_COMMIT && path) {
150 commit = lookup_commit_reference(the_repository, &oid); 153 commit = lookup_commit_reference(the_repository, &oid);
151 read_tree_recursive(the_repository, commit->maybe_tree, 154 read_tree_recursive(the_repository,
152 "", 0, 0, &paths, walk_tree, &walk_tree_ctx); 155 repo_get_commit_tree(the_repository, commit),
156 "", 0, 0, &paths, walk_tree,
157 &walk_tree_ctx);
153 type = oid_object_info(the_repository, &oid, &size); 158 type = oid_object_info(the_repository, &oid, &size);
154 } 159 }
155 160