builtin/revert.c: don't dereference a NULL pointer
cherry-pick will segfault when transplanting a root commit if the --ff option is used. This happens because the "parent" pointer is set to NULL when the commit being cherry-picked has no parents. Later, when "parent" is dereferenced, the cherry-pick segfaults. Fix this by checking whether "parent" is NULL before dereferencing it and add a test for this case of cherry-picking a root commit with --ff. Reported-by: Zbyszek Szmek <zbyszek@in.waw.pl> Signed-off-by: Brandon Casey <casey@nrlssc.navy.mil> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:

committed by
Junio C Hamano

parent
9027fa9eb7
commit
6355e505ba
@ -442,7 +442,7 @@ static int do_pick_commit(void)
|
||||
else
|
||||
parent = commit->parents->item;
|
||||
|
||||
if (allow_ff && !hashcmp(parent->object.sha1, head))
|
||||
if (allow_ff && parent && !hashcmp(parent->object.sha1, head))
|
||||
return fast_forward_to(commit->object.sha1, head);
|
||||
|
||||
if (parent && parse_commit(parent) < 0)
|
||||
|
Reference in New Issue
Block a user