]> git.cameronkatri.com Git - cgit.git/commitdiff
global: use proper accessors for maybe_tree
authorJason A. Donenfeld <Jason@zx2c4.com>
Fri, 13 Mar 2020 02:52:35 +0000 (20:52 -0600)
committerJason A. Donenfeld <Jason@zx2c4.com>
Fri, 13 Mar 2020 23:48:34 +0000 (17:48 -0600)
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>
ui-blame.c
ui-blob.c
ui-commit.c
ui-diff.c
ui-log.c
ui-plain.c
ui-tree.c

index 644c30ad289e79f98b59b49aac1aef18028e9118..f28eea0c74e82e2e67c686496db9905478ac085b 100644 (file)
@@ -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)
index 30e2d4bf5f5484e1a5cd3541e8531f110a1e91f0..f76c641e355bda747dc74e9bfcaa727de284eaaf 100644 (file)
--- 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)
                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);
        }
 
index 9a47b54c560544cf32e0b797614e04c6606eff80..783211ff75deb49aff982e25711efc062f8885c1 100644 (file)
@@ -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(" /");
index c60aefd1d629826e081329713324b7b35b6dff8e..329c3506ac30e2aef6b9f4cdd935e69ef0b49768 100644 (file)
--- a/ui-diff.c
+++ b/ui-diff.c
@@ -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;
        }
index dc5cb1eb6a0b34e7a0cc197cb397fc002248ee1e..2939c0162a394f08ff2feefaca0a3f811ad01b00 100644 (file)
--- a/ui-log.c
+++ b/ui-log.c
@@ -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);
 
index b73c1cfed15fa0350d2004bf17107814f1165867..2a7b18ccd8c55485bf23ad75b3d13f6da65b5daa 100644 (file)
@@ -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)
index 84eb17d6470d718dd99fbe9eb5636967bbaf2226..1e4efb253d2b44ca0adf08ee354cacd3c675e079 100644 (file)
--- a/ui-tree.c
+++ b/ui-tree.c
@@ -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)