about summary refs log tree commit diff stats
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
parentui-snapshot: add support for zstd compression (diff)
downloadcgit-6a8d6d4b5021af6c90ca0da806691987df449469.tar.gz
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>
-rw-r--r--ui-blame.c6
-rw-r--r--ui-blob.c17
-rw-r--r--ui-commit.c2
-rw-r--r--ui-diff.c4
-rw-r--r--ui-log.c4
-rw-r--r--ui-plain.c7
-rw-r--r--ui-tree.c8
7 files changed, 29 insertions, 19 deletions
diff --git a/ui-blame.c b/ui-blame.c index 644c30a..f28eea0 100644 --- a/ui-blame.c +++ b/ui-blame.c
@@ -290,8 +290,10 @@ void cgit_print_blame(void)
290 walk_tree_ctx.match_baselen = (path_items.match) ? 290 walk_tree_ctx.match_baselen = (path_items.match) ?
291 basedir_len(path_items.match) : -1; 291 basedir_len(path_items.match) : -1;
292 292
293 read_tree_recursive(the_repository, commit->maybe_tree, "", 0, 0, 293 read_tree_recursive(the_repository,
294 &paths, walk_tree, &walk_tree_ctx); 294 repo_get_commit_tree(the_repository, commit),
295 "", 0, 0,
296 &paths, walk_tree, &walk_tree_ctx);
295 if (!walk_tree_ctx.state) 297 if (!walk_tree_ctx.state)
296 cgit_print_error_page(404, "Not found", "Not found"); 298 cgit_print_error_page(404, "Not found", "Not found");
297 else if (walk_tree_ctx.state == 2) 299 else if (walk_tree_ctx.state == 2)
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
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)
78 html(")</td></tr>\n"); 78 html(")</td></tr>\n");
79 html("<tr><th>tree</th><td colspan='2' class='sha1'>"); 79 html("<tr><th>tree</th><td colspan='2' class='sha1'>");
80 tmp = xstrdup(hex); 80 tmp = xstrdup(hex);
81 cgit_tree_link(oid_to_hex(&commit->maybe_tree->object.oid), NULL, NULL, 81 cgit_tree_link(oid_to_hex(get_commit_tree_oid(commit)), NULL, NULL,
82 ctx.qry.head, tmp, NULL); 82 ctx.qry.head, tmp, NULL);
83 if (prefix) { 83 if (prefix) {
84 html(" /"); 84 html(" /");
diff --git a/ui-diff.c b/ui-diff.c index c60aefd..329c350 100644 --- a/ui-diff.c +++ b/ui-diff.c
@@ -413,7 +413,7 @@ void cgit_print_diff(const char *new_rev, const char *old_rev,
413 "Bad commit: %s", oid_to_hex(new_rev_oid)); 413 "Bad commit: %s", oid_to_hex(new_rev_oid));
414 return; 414 return;
415 } 415 }
416 new_tree_oid = &commit->maybe_tree->object.oid; 416 new_tree_oid = get_commit_tree_oid(commit);
417 417
418 if (old_rev) { 418 if (old_rev) {
419 if (get_oid(old_rev, old_rev_oid)) { 419 if (get_oid(old_rev, old_rev_oid)) {
@@ -434,7 +434,7 @@ void cgit_print_diff(const char *new_rev, const char *old_rev,
434 "Bad commit: %s", oid_to_hex(old_rev_oid)); 434 "Bad commit: %s", oid_to_hex(old_rev_oid));
435 return; 435 return;
436 } 436 }
437 old_tree_oid = &commit2->maybe_tree->object.oid; 437 old_tree_oid = get_commit_tree_oid(commit2);
438 } else { 438 } else {
439 old_tree_oid = NULL; 439 old_tree_oid = NULL;
440 } 440 }
diff --git a/ui-log.c b/ui-log.c index dc5cb1e..2939c01 100644 --- a/ui-log.c +++ b/ui-log.c
@@ -153,8 +153,8 @@ static int show_commit(struct commit *commit, struct rev_info *revs)
153 rem_lines = 0; 153 rem_lines = 0;
154 154
155 revs->diffopt.flags.recursive = 1; 155 revs->diffopt.flags.recursive = 1;
156 diff_tree_oid(&parent->maybe_tree->object.oid, 156 diff_tree_oid(get_commit_tree_oid(parent),
157 &commit->maybe_tree->object.oid, 157 get_commit_tree_oid(commit),
158 "", &revs->diffopt); 158 "", &revs->diffopt);
159 diffcore_std(&revs->diffopt); 159 diffcore_std(&revs->diffopt);
160 160
diff --git a/ui-plain.c b/ui-plain.c index b73c1cf..2a7b18c 100644 --- a/ui-plain.c +++ b/ui-plain.c
@@ -193,13 +193,14 @@ void cgit_print_plain(void)
193 if (!path_items.match) { 193 if (!path_items.match) {
194 path_items.match = ""; 194 path_items.match = "";
195 walk_tree_ctx.match_baselen = -1; 195 walk_tree_ctx.match_baselen = -1;
196 print_dir(&commit->maybe_tree->object.oid, "", 0, ""); 196 print_dir(get_commit_tree_oid(commit), "", 0, "");
197 walk_tree_ctx.match = 2; 197 walk_tree_ctx.match = 2;
198 } 198 }
199 else 199 else
200 walk_tree_ctx.match_baselen = basedir_len(path_items.match); 200 walk_tree_ctx.match_baselen = basedir_len(path_items.match);
201 read_tree_recursive(the_repository, commit->maybe_tree, 201 read_tree_recursive(the_repository,
202 "", 0, 0, &paths, walk_tree, &walk_tree_ctx); 202 repo_get_commit_tree(the_repository, commit),
203 "", 0, 0, &paths, walk_tree, &walk_tree_ctx);
203 if (!walk_tree_ctx.match) 204 if (!walk_tree_ctx.match)
204 cgit_print_error_page(404, "Not found", "Not found"); 205 cgit_print_error_page(404, "Not found", "Not found");
205 else if (walk_tree_ctx.match == 2) 206 else if (walk_tree_ctx.match == 2)
diff --git a/ui-tree.c b/ui-tree.c index 84eb17d..1e4efb2 100644 --- a/ui-tree.c +++ b/ui-tree.c
@@ -370,12 +370,14 @@ void cgit_print_tree(const char *rev, char *path)
370 walk_tree_ctx.curr_rev = xstrdup(rev); 370 walk_tree_ctx.curr_rev = xstrdup(rev);
371 371
372 if (path == NULL) { 372 if (path == NULL) {
373 ls_tree(&commit->maybe_tree->object.oid, NULL, &walk_tree_ctx); 373 ls_tree(get_commit_tree_oid(commit), NULL, &walk_tree_ctx);
374 goto cleanup; 374 goto cleanup;
375 } 375 }
376 376
377 read_tree_recursive(the_repository, commit->maybe_tree, "", 0, 0, 377 read_tree_recursive(the_repository,
378 &paths, walk_tree, &walk_tree_ctx); 378 repo_get_commit_tree(the_repository, commit),
379 "", 0, 0,
380 &paths, walk_tree, &walk_tree_ctx);
379 if (walk_tree_ctx.state == 1) 381 if (walk_tree_ctx.state == 1)
380 ls_tail(); 382 ls_tail();
381 else if (walk_tree_ctx.state == 2) 383 else if (walk_tree_ctx.state == 2)