From: Toon Claes Date: Tue, 27 Jan 2026 13:26:16 GMT Subject: [PATCH v5 0/4] Fix git-last-modified(1) bug triggered when passing a tree-ish Message-ID: <20260127-toon-last-modified-tree-v5-0-38d18a0956d4@iotcl.com> In-Reply-To: <20260123-toon-last-modified-tree-v4-0-86bf97bad4e2@iotcl.com> Recently there was a bug reported[1] passing a tree OID triggers a BUG: $ git last-modified fb06ce04173d47aaaa498385621cba8b8dfd7584 BUG: builtin/last-modified.c:456: paths remaining beyond boundary in last-modified [1] 690163 IOT instruction (core dumped) git last-modified `fb06ce04173d47aaaa498385621cba8b8dfd7584` is the tree commit id of web_src. I suppose this should've returned a nice error message or blank output. Fix this bug by checking the revision argument. [1]: https://lore.kernel.org/git/03f96860-29fc-42a7-a220-c3ec65eb8516@codeberg.org/ --- Changes in v5: - Use 'commit' instead of 'revision'. - Small typo fixes. - Link to v4: https://patch.msgid.link/20260123-toon-last-modified-tree-v4-0-86bf97bad4e2@iotcl.com Changes in v4: - Extend the error message when revision is not a tree - Extend the test to verify the error message when more than one revision is given. - Link to v3: https://patch.msgid.link/20260116-toon-last-modified-tree-v3-0-e6ade4dc35ab@iotcl.com Changes in v3: - Split the change to plug the leak into a separate commit. - Small changes to commit messages. - Link to v2: https://patch.msgid.link/20260114-toon-last-modified-tree-v2-0-ba3b1860898f@iotcl.com Changes in v2: - Prepend the change with a commit that modifies the error message when more than one revision is given. - Prepend another commit that removes double error message. - Add test to ensure the command works with annotated tags too. - Link to v1: https://patch.msgid.link/20260112-toon-last-modified-tree-v1-1-ecbc78341f76@iotcl.com --- Toon Claes (4): last-modified: rewrite error message when more than one commit given last-modified: fix memory leak when more than one commit is given last-modified: remove double error message last-modified: verify revision argument is a commit-ish builtin/last-modified.c | 19 ++++++++++++++----- t/t8020-last-modified.sh | 24 +++++++++++++++++++----- 2 files changed, 33 insertions(+), 10 deletions(-) Range-diff versus v4: 1: 497901f0ab ! 1: 2107d672e9 last-modified: rewrite error message when more than one revision given @@ Metadata Author: Toon Claes ## Commit message ## - last-modified: rewrite error message when more than one revision given + last-modified: rewrite error message when more than one commit given - When more than one revision is passed to the git-last-modified(1) - command, this error message was printed: + When more than one commit is passed to the git-last-modified(1) command, + this error message was printed: error: last-modified can only operate on one tree at a time @@ Commit message Rephrase the error message to: - error: last-modified can only operate on one revision at a time + error: last-modified can only operate on one commit at a time - While at it, ensure modify the test to ensure the correct error message - is printed. + While at it, modify the test to ensure the correct error message is + printed. Signed-off-by: Toon Claes @@ builtin/last-modified.c: static int populate_paths_from_revs(struct last_modifie if (num_interesting++) - return error(_("last-modified can only operate on one tree at a time")); -+ return error(_("last-modified can only operate on one revision at a time")); ++ return error(_("last-modified can only operate on one commit at a time")); diff_tree_oid(lm->rev.repo->hash_algo->empty_tree, &obj->item->oid, "", &diffopt); @@ t/t8020-last-modified.sh: test_expect_success 'last-modified merge undoes change EOF ' -+test_expect_success 'cannot run last-modified on two revision' ' ++test_expect_success 'cannot run last-modified on two commits' ' + test_must_fail git last-modified HEAD HEAD~1 2>err && -+ test_grep "last-modified can only operate on one revision at a time" err ++ test_grep "last-modified can only operate on one commit at a time" err +' + test_expect_success 'last-modified complains about unknown arguments' ' 2: 1316ca90b4 ! 2: dbabde6b54 last-modified: fix memory leak when more than one revision is given @@ Metadata Author: Toon Claes ## Commit message ## - last-modified: fix memory leak when more than one revision is given + last-modified: fix memory leak when more than one commit is given - When more than one revision is given, the function + When more than one commit is given, the function populate_paths_from_revs() leaks a `struct pathspec`. Plug it. Signed-off-by: Toon Claes @@ builtin/last-modified.c: static int populate_paths_from_revs(struct last_modifie continue; - if (num_interesting++) -- return error(_("last-modified can only operate on one revision at a time")); +- return error(_("last-modified can only operate on one commit at a time")); + if (num_interesting++) { -+ ret = error(_("last-modified can only operate on one revision at a time")); ++ ret = error(_("last-modified can only operate on one commit at a time")); + goto out; + } 3: 151f0ff0ae = 3: 8f37827504 last-modified: remove double error message 4: f2cf0dd371 ! 4: 9a810e12be last-modified: verify revision argument is a commit-ish @@ Metadata ## Commit message ## last-modified: verify revision argument is a commit-ish - Passing a tree OID to git-last-modified(1) would trigger BUG behavior. + Passing a non-committish revision to git-last-modified(1) triggers the + following BUG: 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. + Fix this error by ensuring that the given revision peels to a commit. Reported-by: Gusted Signed-off-by: Toon Claes --- base-commit: ab689ea7f91ab0858e85776f31102203d3ea7b83 change-id: 20260112-toon-last-modified-tree-fdd96b2feaf7