From: Junio C Hamano <gitster@pobox.com>
To: git@vger.kernel.org
Cc: Stephen Boyd <bebarino@gmail.com>, Pierre Habouzit <madcoder@debian.org>
Subject: [PATCH] show-branch: fix segfault when showbranch.default exists
Date: Mon, 08 Jun 2009 23:26:44 -0700 [thread overview]
Message-ID: <7vfxe9udln.fsf@alter.siamese.dyndns.org> (raw)
When running "git show-branch" without any parameter in a repository that
has showbranch.default defined, we used to rely on the fact that our
handcrafted option parsing loop never looked at av[0].
The array of default strings had the first real command line argument in
default_arg[0], but the option parser wanted to look at the array starting
at av[1], so we assigned the address of -1th element to av to force the
loop start working from default_arg[0].
This no longer worked since 5734365 (show-branch: migrate to parse-options
API, 2009-05-21), as parse_options_start() saved the incoming &av[0] in
its ctx->out and later in parse_options_end() it did memmove to ctx->out
(with ctx->cpidx == 0), overwriting the memory before default_arg[] array.
I am not sure if this is a bug in parse_options(), or a bug in the caller,
and tonight I do not have enough concentration to figure out which. In
any case, this patch works the issue around.
Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
builtin-show-branch.c | 14 +++++++++++---
1 files changed, 11 insertions(+), 3 deletions(-)
diff --git a/builtin-show-branch.c b/builtin-show-branch.c
index 01bea3b..baec9ed 100644
--- a/builtin-show-branch.c
+++ b/builtin-show-branch.c
@@ -565,7 +565,15 @@ static int git_show_branch_config(const char *var, const char *value, void *cb)
if (!strcmp(var, "showbranch.default")) {
if (!value)
return config_error_nonbool(var);
- if (default_alloc <= default_num + 1) {
+ /*
+ * default_arg is now passed to parse_options(), so we need to
+ * mimick the real argv a bit better.
+ */
+ if (!default_num) {
+ default_alloc = 20;
+ default_arg = xcalloc(default_alloc, sizeof(*default_arg));
+ default_arg[default_num++] = "show-branch";
+ } else if (default_alloc <= default_num + 1) {
default_alloc = default_alloc * 3 / 2 + 20;
default_arg = xrealloc(default_arg, sizeof *default_arg * default_alloc);
}
@@ -692,8 +700,8 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)
/* If nothing is specified, try the default first */
if (ac == 1 && default_num) {
- ac = default_num + 1;
- av = default_arg - 1; /* ick; we would not address av[0] */
+ ac = default_num;
+ av = default_arg;
}
ac = parse_options(ac, av, prefix, builtin_show_branch_options,
next reply other threads:[~2009-06-09 6:26 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-06-09 6:26 Junio C Hamano [this message]
2009-06-09 7:17 ` [PATCH] show-branch: fix segfault when showbranch.default exists Stephen Boyd
2009-06-09 8:06 ` Pierre Habouzit
2009-06-09 16:28 ` Junio C Hamano
2009-06-09 17:23 ` Pierre Habouzit
2009-06-09 17:35 ` branch management Harry Duin
2009-06-09 19:50 ` Alex Riesen
2009-06-10 14:02 ` Harry Duin
2009-06-10 14:43 ` Jakub Narebski
2009-06-10 15:28 ` Nicolas Pitre
2009-06-10 17:37 ` Linus Torvalds
2009-06-10 19:14 ` Daniel Barkalow
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=7vfxe9udln.fsf@alter.siamese.dyndns.org \
--to=gitster@pobox.com \
--cc=bebarino@gmail.com \
--cc=git@vger.kernel.org \
--cc=madcoder@debian.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).