git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Elijah Newren <newren@gmail.com>
To: git@vger.kernel.org
Cc: gitster@pobox.com, B.Steinbrink@gmx.de, Elijah Newren <newren@gmail.com>
Subject: [PATCH 2/2] rev-parse: verify that commit looked up is not NULL
Date: Wed, 23 May 2018 13:46:13 -0700	[thread overview]
Message-ID: <20180523204613.11333-2-newren@gmail.com> (raw)
In-Reply-To: <20180523204613.11333-1-newren@gmail.com>

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 <newren@gmail.com>
---
 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


  reply	other threads:[~2018-05-23 20:46 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-05-23 19:52 BUG: rev-parse segfault with invalid input Todd Zullinger
2018-05-23 20:23 ` Elijah Newren
2018-05-23 20:45   ` Todd Zullinger
2018-05-23 20:46   ` [PATCH 1/2] t6101: add a test for rev-parse $garbage^@ Elijah Newren
2018-05-23 20:46     ` Elijah Newren [this message]
2018-05-23 22:09       ` [PATCH 2/2] rev-parse: verify that commit looked up is not NULL Jeff King
2018-05-24  6:27         ` [PATCH v2] rev-parse: check lookup'ed commit references for NULL Elijah Newren
2018-05-24 14:04           ` Todd Zullinger
2018-05-24 15:11             ` Florian Weimer
2018-05-24 17:06           ` Jeff King
2018-05-25  1:07           ` Junio C Hamano
2018-05-23 22:19       ` [PATCH 2/2] rev-parse: verify that commit looked up is not NULL Todd Zullinger
2018-05-23 22:23         ` Todd Zullinger
2018-05-23 22:12     ` [PATCH 1/2] t6101: add a test for rev-parse $garbage^@ Jeff King

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180523204613.11333-2-newren@gmail.com \
    --to=newren@gmail.com \
    --cc=B.Steinbrink@gmx.de \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).