From: Zbyszek Szmek <zbyszek@in.waw.pl>
To: Brandon Casey <casey@nrlssc.navy.mil>
Cc: gitster@pobox.com, git@vger.kernel.org,
Brandon Casey <drafnel@gmail.com>
Subject: Re: [PATCH] builtin/revert.c: don't dereference a NULL pointer
Date: Tue, 28 Sep 2010 12:03:40 +0200 [thread overview]
Message-ID: <20100928100340.GC6756@in.waw.pl> (raw)
In-Reply-To: <op5xt5mU5aQhqmO9a_49Hhsxhtg2iW_beFHkzibXMWI534-yRKsOVCvL_25O3xS3R6hTEbD06Kc@cipher.nrlssc.navy.mil>
Works as advertised. Tests also pass.
Thanks,
Zbyszek
On Mon, Sep 27, 2010 at 12:29:45PM -0500, Brandon Casey wrote:
> From: Brandon Casey <drafnel@gmail.com>
>
> 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>
> ---
> builtin/revert.c | 2 +-
> t/t3506-cherry-pick-ff.sh | 10 ++++++++++
> 2 files changed, 11 insertions(+), 1 deletions(-)
>
> diff --git a/builtin/revert.c b/builtin/revert.c
> index 4b47ace..57b51e4 100644
> --- a/builtin/revert.c
> +++ b/builtin/revert.c
> @@ -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)
> diff --git a/t/t3506-cherry-pick-ff.sh b/t/t3506-cherry-pick-ff.sh
> index e17ae71..51ca391 100755
> --- a/t/t3506-cherry-pick-ff.sh
> +++ b/t/t3506-cherry-pick-ff.sh
> @@ -95,4 +95,14 @@ test_expect_success 'cherry pick a merge relative to nonexistent parent with --f
> test_must_fail git cherry-pick --ff -m 3 C
> '
>
> +test_expect_success 'cherry pick a root commit with --ff' '
> + git reset --hard first -- &&
> + git rm file1 &&
> + echo first >file2 &&
> + git add file2 &&
> + git commit --amend -m "file2" &&
> + git cherry-pick --ff first &&
> + test "$(git rev-parse --verify HEAD)" = "1df192cd8bc58a2b275d842cede4d221ad9000d1"
> +'
> +
> test_done
> --
> 1.7.3
prev parent reply other threads:[~2010-09-28 10:03 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-09-27 14:23 rebase -i segmentation fault and another problem Zbyszek Szmek
2010-09-27 16:01 ` Brandon Casey
2010-09-27 17:29 ` [PATCH] builtin/revert.c: don't dereference a NULL pointer Brandon Casey
2010-09-28 10:03 ` Zbyszek Szmek [this message]
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=20100928100340.GC6756@in.waw.pl \
--to=zbyszek@in.waw.pl \
--cc=casey@nrlssc.navy.mil \
--cc=drafnel@gmail.com \
--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).