]> git.ipfire.org Git - thirdparty/git.git/commitdiff
last-modified: verify revision argument is a commit-ish
authorToon Claes <toon@iotcl.com>
Fri, 16 Jan 2026 13:08:40 +0000 (14:08 +0100)
committerJunio C Hamano <gitster@pobox.com>
Fri, 16 Jan 2026 17:30:27 +0000 (09:30 -0800)
Passing a tree OID to git-last-modified(1) would trigger BUG behavior.

    git last-modified HEAD^{tree}
    BUG: builtin/last-modified.c:456: paths remaining beyond boundary in last-modified

Fix this error by verifying the parsed revision is a commit-ish.

Reported-by: Gusted <gusted@codeberg.org>
Signed-off-by: Toon Claes <toon@iotcl.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/last-modified.c
t/t8020-last-modified.sh

index 0df85be31876b0dc6a8c698d6fd9d08a1bb2367b..5366cedd0fcb0137207957b174a989abec3b77c4 100644 (file)
@@ -150,6 +150,11 @@ static int populate_paths_from_revs(struct last_modified *lm)
                        goto out;
                }
 
+               if (!repo_peel_to_type(lm->rev.repo, obj->path, 0, obj->item, OBJ_COMMIT)) {
+                       ret = error(_("revision argument is not a commit-ish"));
+                       goto out;
+               }
+
                diff_tree_oid(lm->rev.repo->hash_algo->empty_tree,
                              &obj->item->oid, "", &diffopt);
                diff_flush(&diffopt);
index 1183ae667bd17d4121a7b007b31867717e140958..22635de4476e81e7aaddab62d542ec77cf67a578 100755 (executable)
@@ -8,6 +8,7 @@ test_expect_success 'setup' '
        test_commit 1 file &&
        mkdir a &&
        test_commit 2 a/file &&
+       git tag -mA t2 2 &&
        mkdir a/b &&
        test_commit 3 a/b/file
 '
@@ -55,6 +56,13 @@ test_expect_success 'last-modified recursive' '
        EOF
 '
 
+test_expect_success 'last-modified on annotated tag' '
+       check_last_modified t2 <<-\EOF
+       2 a
+       1 file
+       EOF
+'
+
 test_expect_success 'last-modified recursive with show-trees' '
        check_last_modified -r -t <<-\EOF
        3 a/b
@@ -235,4 +243,9 @@ test_expect_success 'last-modified complains about unknown arguments' '
        grep "unknown last-modified argument: --foo" err
 '
 
+test_expect_success 'last-modified expects commit-ish' '
+       test_must_fail git last-modified HEAD^{tree} 2>err &&
+       grep "revision argument is not a commit-ish" err
+'
+
 test_done