git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] Reserve a slot for argv[0] in default_arg.
@ 2009-10-03 13:29 Petter Urkedal
  2009-10-04 13:33 ` Jeff King
  0 siblings, 1 reply; 10+ messages in thread
From: Petter Urkedal @ 2009-10-03 13:29 UTC (permalink / raw)
  To: git; +Cc: Petter Urkedal

Setting "av" to one slot before the allocated "default_arg" array causes
glibc abort with "free(): invalid next size (normal)" in some
configurations (Gentoo, glibc-2.9_p20081201-r2, gcc-5.3.2 with PIE).
---
 builtin-show-branch.c |    7 +++++--
 1 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/builtin-show-branch.c b/builtin-show-branch.c
index 3510a86..3ab72b7 100644
--- a/builtin-show-branch.c
+++ b/builtin-show-branch.c
@@ -568,6 +568,9 @@ static int git_show_branch_config(const char *var, const char *value, void *cb)
 		if (default_alloc <= default_num + 1) {
 			default_alloc = default_alloc * 3 / 2 + 20;
 			default_arg = xrealloc(default_arg, sizeof *default_arg * default_alloc);
+			if (!default_num)
+			    /* One unused position for argv[0]. */
+			    default_arg[default_num++] = NULL;
 		}
 		default_arg[default_num++] = xstrdup(value);
 		default_arg[default_num] = NULL;
@@ -692,8 +695,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,
-- 
1.6.4.4

^ permalink raw reply related	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2009-10-05 18:49 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-10-03 13:29 [PATCH] Reserve a slot for argv[0] in default_arg Petter Urkedal
2009-10-04 13:33 ` Jeff King
2009-10-04 14:13   ` Petter Urkedal
2009-10-04 18:27     ` Jeff King
2009-10-04 20:02       ` Stephen Boyd
2009-10-04 22:20       ` Junio C Hamano
2009-10-05  6:36         ` Petter Urkedal
2009-10-05 18:45           ` Jeff King
2009-10-05  6:44       ` Petter Urkedal
2009-10-04 14:51   ` Petter Urkedal

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).