In commit 2122f8b963d4 ("rev-parse: Add support for the ^! and ^@ syntax",
2008-07-26), try_parent_shorthands() was introduced to parse the special
^! and ^@ syntax. However, it did not check the commit returned from
lookup_commit_reference() before proceeding to use it. If it is NULL,
bail early and notify the caller that this cannot be a valid revision
range.
Signed-off-by: Elijah Newren <[email protected]>
---
builtin/rev-parse.c | 2 ++
t/t6101-rev-parse-parents.sh | 2 +-
2 files changed, 3 insertions(+), 1 deletion(-)
diff --git a/builtin/rev-parse.c b/builtin/rev-parse.c
index 55c0b90441..4e9ba9641a 100644
--- a/builtin/rev-parse.c
+++ b/builtin/rev-parse.c
@@ -334,6 +334,8 @@ static int try_parent_shorthands(const char *arg)
}
commit = lookup_commit_reference(&oid);
+ if (!commit)
+ return 1;
if (exclude_parent &&
exclude_parent > commit_list_count(commit->parents)) {
*dotdot = '^';
diff --git a/t/t6101-rev-parse-parents.sh b/t/t6101-rev-parse-parents.sh
index 7b1b2dbdf2..f91cc417bd 100755
--- a/t/t6101-rev-parse-parents.sh
+++ b/t/t6101-rev-parse-parents.sh
@@ -214,7 +214,7 @@ test_expect_success 'rev-list merge^-1x (garbage after
^-1)' '
test_must_fail git rev-list merge^-1x
'
-test_expect_failure 'rev-parse $garbage^@ should not segfault' '
+test_expect_success 'rev-parse $garbage^@ should not segfault' '
git rev-parse ffffffffffffffffffffffffffffffffffffffff^@
'
--
2.17.0.1025.g36b5c64692