git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* BUG: rev-parse segfault with invalid input
@ 2018-05-23 19:52 Todd Zullinger
  2018-05-23 20:23 ` Elijah Newren
  0 siblings, 1 reply; 14+ messages in thread
From: Todd Zullinger @ 2018-05-23 19:52 UTC (permalink / raw)
  To: git; +Cc: Jeff King, Junio C Hamano

Hi,

Certain invalid input causes git rev-parse to crash rather
than return a 'fatal: ambiguous argument ...' error.

This was reported against the Fedora git package:

    https://bugzilla.redhat.com/1581678

Simple reproduction recipe and analysis, from the bug:

    $ git init
    Initialized empty Git repository in /tmp/t/.git/
    $ git rev-parse ffffffffffffffffffffffffffffffffffffffff^@
    Segmentation fault (core dumped)

    gdb) break lookup_commit_reference
    Breakpoint 1 at 0x555555609f00: lookup_commit_reference. (3 locations)
    (gdb) r
    Starting program: /usr/bin/git rev-parse ffffffffffffffffffffffffffffffffffffffff\^@
    [Thread debugging using libthread_db enabled]
    Using host libthread_db library "/lib64/libthread_db.so.1".

    Breakpoint 1, lookup_commit_reference (oid=oid@entry=0x7fffffffd550) at commit.c:34
    34              return lookup_commit_reference_gently(oid, 0);
    (gdb) finish
    Run till exit from #0  lookup_commit_reference (oid=oid@entry=0x7fffffffd550) at commit.c:34
    try_parent_shorthands (arg=0x7fffffffdd44 'f' <repeats 40 times>) at builtin/rev-parse.c:314
    314                     include_parents = 1;
    Value returned is $1 = (struct commit *) 0x0
    (gdb) c

    (gdb) c
    Continuing.

    Program received signal SIGSEGV, Segmentation fault.
    try_parent_shorthands (arg=0x7fffffffdd44 'f' <repeats 40 times>) at builtin/rev-parse.c:345
    345             for (parents = commit->parents, parent_number = 1;
    (gdb) l 336,+15
    336             commit = lookup_commit_reference(&oid);
    337             if (exclude_parent &&
    338                 exclude_parent > commit_list_count(commit->parents)) {
    339                     *dotdot = '^';
    340                     return 0;
    341             }
    342     
    343             if (include_rev)
    344                     show_rev(NORMAL, &oid, arg);
    345             for (parents = commit->parents, parent_number = 1;
    346                  parents;
    347                  parents = parents->next, parent_number++) {
    348                     char *name = NULL;
    349     
    350                     if (exclude_parent && parent_number != exclude_parent)
    351                             continue;

    Looks like a null pointer check is missing.

This occurs on master and as far back as 1.8.3.1 (what's in
RHEL-6, I didn't try to test anything older).  Only a string
with 40 valid hex characters and ^@, @-, of ^!  seems to
trigger it.

-- 
Todd
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
I don't mind arguing with myself. It's when I lose that it bothers me.
    -- Richard Powers


^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2018-05-25  1:07 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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     ` [PATCH 2/2] rev-parse: verify that commit looked up is not NULL Elijah Newren
2018-05-23 22:09       ` 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

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).