Skip to content

Commit 6a8d6d4

Browse files
committed
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 <[email protected]> Signed-off-by: Jason A. Donenfeld <[email protected]>
1 parent 892ba8c commit 6a8d6d4

File tree

7 files changed

+29
-19
lines changed

7 files changed

+29
-19
lines changed

ui-blame.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -290,8 +290,10 @@ void cgit_print_blame(void)
290290
walk_tree_ctx.match_baselen = (path_items.match) ?
291291
basedir_len(path_items.match) : -1;
292292

293-
read_tree_recursive(the_repository, commit->maybe_tree, "", 0, 0,
294-
&paths, walk_tree, &walk_tree_ctx);
293+
read_tree_recursive(the_repository,
294+
repo_get_commit_tree(the_repository, commit),
295+
"", 0, 0,
296+
&paths, walk_tree, &walk_tree_ctx);
295297
if (!walk_tree_ctx.state)
296298
cgit_print_error_page(404, "Not found", "Not found");
297299
else if (walk_tree_ctx.state == 2)

ui-blob.c

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,9 @@ int cgit_ref_path_exists(const char *path, const char *ref, int file_only)
5656
goto done;
5757
if (oid_object_info(the_repository, &oid, &size) != OBJ_COMMIT)
5858
goto done;
59-
read_tree_recursive(the_repository, lookup_commit_reference(the_repository, &oid)->maybe_tree,
60-
"", 0, 0, &paths, walk_tree, &walk_tree_ctx);
59+
read_tree_recursive(the_repository,
60+
repo_get_commit_tree(the_repository, lookup_commit_reference(the_repository, &oid)),
61+
"", 0, 0, &paths, walk_tree, &walk_tree_ctx);
6162

6263
done:
6364
free(path_items.match);
@@ -91,8 +92,10 @@ int cgit_print_file(char *path, const char *head, int file_only)
9192
type = oid_object_info(the_repository, &oid, &size);
9293
if (type == OBJ_COMMIT) {
9394
commit = lookup_commit_reference(the_repository, &oid);
94-
read_tree_recursive(the_repository, commit->maybe_tree,
95-
"", 0, 0, &paths, walk_tree, &walk_tree_ctx);
95+
read_tree_recursive(the_repository,
96+
repo_get_commit_tree(the_repository, commit),
97+
"", 0, 0, &paths, walk_tree,
98+
&walk_tree_ctx);
9699
if (!walk_tree_ctx.found_path)
97100
return -1;
98101
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
148151

149152
if ((!hex) && type == OBJ_COMMIT && path) {
150153
commit = lookup_commit_reference(the_repository, &oid);
151-
read_tree_recursive(the_repository, commit->maybe_tree,
152-
"", 0, 0, &paths, walk_tree, &walk_tree_ctx);
154+
read_tree_recursive(the_repository,
155+
repo_get_commit_tree(the_repository, commit),
156+
"", 0, 0, &paths, walk_tree,
157+
&walk_tree_ctx);
153158
type = oid_object_info(the_repository, &oid, &size);
154159
}
155160

ui-commit.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ void cgit_print_commit(char *hex, const char *prefix)
7878
html(")</td></tr>\n");
7979
html("<tr><th>tree</th><td colspan='2' class='sha1'>");
8080
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,
8282
ctx.qry.head, tmp, NULL);
8383
if (prefix) {
8484
html(" /");

ui-diff.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,7 @@ void cgit_print_diff(const char *new_rev, const char *old_rev,
413413
"Bad commit: %s", oid_to_hex(new_rev_oid));
414414
return;
415415
}
416-
new_tree_oid = &commit->maybe_tree->object.oid;
416+
new_tree_oid = get_commit_tree_oid(commit);
417417

418418
if (old_rev) {
419419
if (get_oid(old_rev, old_rev_oid)) {
@@ -434,7 +434,7 @@ void cgit_print_diff(const char *new_rev, const char *old_rev,
434434
"Bad commit: %s", oid_to_hex(old_rev_oid));
435435
return;
436436
}
437-
old_tree_oid = &commit2->maybe_tree->object.oid;
437+
old_tree_oid = get_commit_tree_oid(commit2);
438438
} else {
439439
old_tree_oid = NULL;
440440
}

ui-log.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,8 @@ static int show_commit(struct commit *commit, struct rev_info *revs)
153153
rem_lines = 0;
154154

155155
revs->diffopt.flags.recursive = 1;
156-
diff_tree_oid(&parent->maybe_tree->object.oid,
157-
&commit->maybe_tree->object.oid,
156+
diff_tree_oid(get_commit_tree_oid(parent),
157+
get_commit_tree_oid(commit),
158158
"", &revs->diffopt);
159159
diffcore_std(&revs->diffopt);
160160

ui-plain.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -193,13 +193,14 @@ void cgit_print_plain(void)
193193
if (!path_items.match) {
194194
path_items.match = "";
195195
walk_tree_ctx.match_baselen = -1;
196-
print_dir(&commit->maybe_tree->object.oid, "", 0, "");
196+
print_dir(get_commit_tree_oid(commit), "", 0, "");
197197
walk_tree_ctx.match = 2;
198198
}
199199
else
200200
walk_tree_ctx.match_baselen = basedir_len(path_items.match);
201-
read_tree_recursive(the_repository, commit->maybe_tree,
202-
"", 0, 0, &paths, walk_tree, &walk_tree_ctx);
201+
read_tree_recursive(the_repository,
202+
repo_get_commit_tree(the_repository, commit),
203+
"", 0, 0, &paths, walk_tree, &walk_tree_ctx);
203204
if (!walk_tree_ctx.match)
204205
cgit_print_error_page(404, "Not found", "Not found");
205206
else if (walk_tree_ctx.match == 2)

ui-tree.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -370,12 +370,14 @@ void cgit_print_tree(const char *rev, char *path)
370370
walk_tree_ctx.curr_rev = xstrdup(rev);
371371

372372
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);
374374
goto cleanup;
375375
}
376376

377-
read_tree_recursive(the_repository, commit->maybe_tree, "", 0, 0,
378-
&paths, walk_tree, &walk_tree_ctx);
377+
read_tree_recursive(the_repository,
378+
repo_get_commit_tree(the_repository, commit),
379+
"", 0, 0,
380+
&paths, walk_tree, &walk_tree_ctx);
379381
if (walk_tree_ctx.state == 1)
380382
ls_tail();
381383
else if (walk_tree_ctx.state == 2)

0 commit comments

Comments
 (0)