From: Stephan Beyer <s-beyer@gmx.net>
To: git@vger.kernel.org
Cc: Johannes Schindelin <Johannes.Schindelin@gmx.de>,
Paolo Bonzini <bonzini@gnu.org>,
Miklos Vajna <vmiklos@frugalware.org>,
"Shawn O. Pearce" <spearce@spearce.org>,
Daniel Barkalow <barkalow@iabervon.org>,
Christian Couder <chriscool@tuxfamily.org>,
gitster@pobox.com, Stephan Beyer <s-beyer@gmx.net>
Subject: [PATCH v2 1/5] checkout: don't crash on file checkout before running post-checkout hook
Date: Fri, 16 Jan 2009 20:09:58 +0100 [thread overview]
Message-ID: <1232133002-21725-1-git-send-email-s-beyer@gmx.net> (raw)
In-Reply-To: <20090116172521.GD28177@leksak.fem-net>
In the case of
git init
echo exit >.git/hooks/post-checkout
chmod +x .git/hooks/post-checkout
touch foo
git add foo
rm foo
git checkout -- foo
git-checkout resulted in a Segmentation fault, because there is no new
branch set for the post-checkout hook.
This patch makes use of the null SHA as it is set for the old branch.
While at it, I removed the xstrdup() around the sha1_to_hex(...) calls
in builtin-checkout.c/post_checkout_hook() because sha1_to_hex()
uses four buffers for the hex-dumped SHA and we only need two.
(Duplicating one buffer is only needed if we need more than four.)
Signed-off-by: Stephan Beyer <s-beyer@gmx.net>
---
I checked if all run_hook()-like functions in the code are
addressed with my patch and found that the one in builtin-checkout.c
isn't. Then I stumbled over this rare-case bug.
builtin-checkout.c | 6 ++++--
1 files changed, 4 insertions(+), 2 deletions(-)
diff --git a/builtin-checkout.c b/builtin-checkout.c
index b5dd9c0..149343e 100644
--- a/builtin-checkout.c
+++ b/builtin-checkout.c
@@ -47,8 +47,10 @@ static int post_checkout_hook(struct commit *old, struct commit *new,
memset(&proc, 0, sizeof(proc));
argv[0] = name;
- argv[1] = xstrdup(sha1_to_hex(old ? old->object.sha1 : null_sha1));
- argv[2] = xstrdup(sha1_to_hex(new->object.sha1));
+ argv[1] = sha1_to_hex(old ? old->object.sha1 : null_sha1);
+ argv[2] = sha1_to_hex(new ? new->object.sha1 : null_sha1);
+ /* "new" can be NULL when checking out from the index before
+ a commit exists. */
argv[3] = changed ? "1" : "0";
argv[4] = NULL;
proc.argv = argv;
--
1.6.1.160.gecdb
next prev parent reply other threads:[~2009-01-16 19:12 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-01-15 15:00 [PATCH 1/2] Move run_hook() from builtin-commit.c into run-command.c (libgit) Stephan Beyer
2009-01-15 15:00 ` [PATCH 2/2] api-run-command.txt: talk about run_hook() Stephan Beyer
2009-01-15 15:49 ` Jakub Narebski
2009-01-15 16:12 ` Miklos Vajna
2009-01-15 15:46 ` [PATCH 1/2] Move run_hook() from builtin-commit.c into run-command.c (libgit) Johannes Schindelin
2009-01-15 22:59 ` Junio C Hamano
2009-01-16 17:25 ` Stephan Beyer
2009-01-16 19:09 ` Stephan Beyer [this message]
2009-01-16 19:09 ` [PATCH v2 2/5] " Stephan Beyer
2009-01-16 19:10 ` [PATCH v2 3/5] api-run-command.txt: talk about run_hook() Stephan Beyer
2009-01-16 19:10 ` [PATCH v2 4/5] run_hook(): check the executability of the hook before filling argv Stephan Beyer
2009-01-16 19:10 ` [PATCH 5/5] run_hook(): allow more than 9 hook arguments Stephan Beyer
2009-01-16 21:05 ` Johannes Schindelin
2009-01-17 3:02 ` [PATCH v2 " Stephan Beyer
2009-01-18 1:56 ` [PATCH v2 1/5] checkout: don't crash on file checkout before running post-checkout hook Junio C Hamano
2009-01-18 2:05 ` Stephan Beyer
2009-01-16 20:58 ` [PATCH 1/2] Move run_hook() from builtin-commit.c into run-command.c (libgit) Johannes Schindelin
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=1232133002-21725-1-git-send-email-s-beyer@gmx.net \
--to=s-beyer@gmx.net \
--cc=Johannes.Schindelin@gmx.de \
--cc=barkalow@iabervon.org \
--cc=bonzini@gnu.org \
--cc=chriscool@tuxfamily.org \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=spearce@spearce.org \
--cc=vmiklos@frugalware.org \
/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).