From: "Jose Ivan B. Vilarouca Filho" <joseivan@lavid.ufpb.br>
To: sunshine@sunshineco.com
Cc: git@vger.kernel.org,
"Jose Ivan B. Vilarouca Filho" <joseivan@lavid.ufpb.br>
Subject: Re: [PATCH] Fixing segmentation fault when merging FETCH_HEAD
Date: Sun, 20 Mar 2016 20:11:42 -0400 [thread overview]
Message-ID: <1458519102-32621-1-git-send-email-joseivan@lavid.ufpb.br> (raw)
In-Reply-To: <CAPig+cRVtzLjKTW7FZ-h8thEXkTqBJtbSwpKJs3+wdRHYV1qrQ@mail.gmail.com>
From: "Jose Ivan B. Vilarouca Filho" <joseivan@lavid.ufpb.br>
Hello, Eric.
Thanks for suggestions. I've added a test in commit replacing git fetch origin by a fake FETCH_HEAD content.
merge: don't dereference NULL pointer
A segmentaion fault is raised when trying to merge FETCH_HEAD
formed only by "not-for-merge" refs.
Ex:
git init .
git remote add origin ...
git fetch origin
git merge FETCH_HEAD
Signed-off-by: Jose Ivan B. Vilarouca Filho <joseivan@lavid.ufpb.br>
---
builtin/merge.c | 4 ++--
test-merge-fetchhead.sh | 23 +++++++++++++++++++++++
2 files changed, 25 insertions(+), 2 deletions(-)
create mode 100755 test-merge-fetchhead.sh
diff --git a/builtin/merge.c b/builtin/merge.c
index 101ffef..098aa8a 100644
--- a/builtin/merge.c
+++ b/builtin/merge.c
@@ -1270,9 +1270,9 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
"an empty head"));
remoteheads = collect_parents(head_commit, &head_subsumed,
argc, argv, NULL);
- remote_head = remoteheads->item;
- if (!remote_head)
+ if (!remoteheads || !remoteheads->item)
die(_("%s - not something we can merge"), argv[0]);
+ remote_head = remoteheads->item;
if (remoteheads->next)
die(_("Can merge only exactly one commit into empty head"));
read_empty(remote_head->object.oid.hash, 0);
diff --git a/test-merge-fetchhead.sh b/test-merge-fetchhead.sh
new file mode 100755
index 0000000..383415a
--- /dev/null
+++ b/test-merge-fetchhead.sh
@@ -0,0 +1,23 @@
+#!/bin/bash
+GIT=$(pwd)/git
+REPO_DIR=./test-fetch-head-repo
+
+if [ ! -x "${GIT}" ]; then
+ echo "Missing git binary"
+ exit 1
+fi
+
+${GIT} init ${REPO_DIR} || rm -rf ${REPO_DIR} || exit 1
+pushd ${REPO_DIR} || rm -rf ${REPO_DIR} || exit 1
+#Let's fake a FETCH_HEAD only formed by not-for-merge (git fetch origin)
+echo -ne "f954fc9919c9ec33179e11aa1af562384677e174\tnot-for-merge\tbranch 'master' of https://github.com/git/git.git" > .git/FETCH_HEAD
+${GIT} merge FETCH_HEAD
+GRET=$?
+popd
+if [ ${GRET} -eq 139 ]; then
+ rm -rf ${REPO_DIR}
+ exit 1
+fi
+
+rm -rf ${REPO_DIR}
+exit 0
--
1.7.10.4
next prev parent reply other threads:[~2016-03-21 0:12 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-03-19 18:17 [PATCH] Fixing segmentation fault when merging FETCH_HEAD Jose Ivan B. Vilarouca Filho
2016-03-20 1:23 ` Eric Sunshine
2016-03-21 0:11 ` Jose Ivan B. Vilarouca Filho [this message]
2016-03-21 6:40 ` Eric Sunshine
2016-03-21 19:01 ` merge: fix NULL pointer dereference when merging nothing into void Junio C Hamano
2016-03-21 19:36 ` Eric Sunshine
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
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1458519102-32621-1-git-send-email-joseivan@lavid.ufpb.br \
--to=joseivan@lavid.ufpb.br \
--cc=git@vger.kernel.org \
--cc=sunshine@sunshineco.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.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
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 read-only IMAP folder(s) and NNTP newsgroup(s).