Subject: Segfault in git reflog

From: Dennis Kaarsemaker <[email-masked]>
Date: Wed, 30 Dec 2015 10:24:01 +0100

I've hit a segfault in git reflog with latest git, reproducable in git.git:

spirit:~/code/git (master)$ ./git describe
v2.7.0-rc3

I've minimized the reflog to:

spirit:~/code/git (master)$ cat .git/logs/HEAD
2635c2b8bfc9aec07b7f023d8e3b3d02df715344 54bc41416c5d3ecb978acb0df80d57aa3e54494c Dennis Kaarsemaker <[email-masked]> 1446765642 +0100  
74c855f87d25a5b5c12d0485ec77c785a1c734c5 54bc41416c5d3ecb978acb0df80d57aa3e54494c Dennis Kaarsemaker <[email-masked]> 1446765951 +0100  checkout: moving from 3c3d3f629a6176b401ebec455c5dd59ed1b5f910 to master

...which I realize looks a bit broken. I think at the time I was playing with
some patches that also caused segfaults, causing gaps in the reflog.
Nevertheless, I think segfaulting is bad. All objects in the reflog are
reachable.

gdb has the following to say:

spirit:~/code/git (master)$ gdb --args ./git --no-pager reflog
(gdb) run
Starting program: /home/dennis/code/git/git --no-pager reflog
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
28274d0 (HEAD -> master, tag: v2.7.0-rc3, upstream/master, peff/jk/tag-source-propagate, peff/jk/sigpipe-report, gitster/master) HEAD@{0}: checkout: moving from 3c3d3f629a6176b401ebec455c5dd59ed1b5f910 to master

Program received signal SIGSEGV, Segmentation fault.
copy_commit_list (list=0x4834dc7000000011) at commit.c:450
450         pp = commit_list_append(list->item, pp);
(gdb) bt
#0  copy_commit_list (list=0x4834dc7000000011) at commit.c:450
#1  0x000000000050705e in save_parents (commit=commit@entry=0x928a90, revs=0x7fffffffcb80) at revision.c:3044
#2  0x000000000050a54e in get_revision_1 (revs=revs@entry=0x7fffffffcb80) at revision.c:3119
#3  0x000000000050a710 in get_revision_1 (revs=<optimized out>) at revision.c:3112
#4  get_revision_internal (revs=0x7fffffffcb80) at revision.c:3248
#5  0x000000000050a99d in get_revision (revs=revs@entry=0x7fffffffcb80) at revision.c:3322
#6  0x0000000000446032 in cmd_log_walk (rev=rev@entry=0x7fffffffcb80) at builtin/log.c:344
#7  0x0000000000446bf8 in cmd_log_reflog (argc=1, argv=0x7fffffffd6a8, prefix=0x0) at builtin/log.c:626
#8  0x0000000000406126 in run_builtin (argv=0x7fffffffd6a8, argc=1, p=0x7bbec0 <commands+1920>) at git.c:350
#9  handle_builtin (argc=1, argv=0x7fffffffd6a8) at git.c:536
#10 0x0000000000405261 in run_argv (argv=0x7fffffffd4c8, argcp=0x7fffffffd4ac) at git.c:582
#11 main (argc=1, av=<optimized out>) at git.c:690
(gdb) p list
$1 = (struct commit_list *) 0x4834dc7000000011
(gdb) p list->item
Cannot access memory at address 0x4834dc7000000011

A bisect blames 53d00b3 (log: use true parents for diff even when rewriting),
which does indeed touch the code that seems to be segfaulting.

I've tried digging into this, but didn't get very far.
-- 
Dennis Kaarsemaker <[email-masked]>