From dfef873f3ddbabf5d380d679e9b76d033b14e01a Mon Sep 17 00:00:00 2001 From: Brandon Casey Date: Thu, 16 Jul 2009 16:26:15 -0500 Subject: [PATCH] branch.c: if remote is not config'd for branch, don't try delete push config If a remote is not configured for the branch configuration being deleted, then don't try to delete the remote..push configuration for the branch. When the remote is not configured, branch->remote_name is not filled in. When this NULL branch->remote_name is passed to strbuf_addf() it will result in an attempt to remove a bogus configuration statement in the best case (i.e. "remote.(null).push" for platforms which guard against supplying NULL to a %s conversion spec) and a segfault in the worst case. So check whether branch->remote_name is non-NULL before trying to use it. Signed-off-by: Brandon Casey Signed-off-by: Junio C Hamano --- branch.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/branch.c b/branch.c index dfde568ae8..ae215307a6 100644 --- a/branch.c +++ b/branch.c @@ -116,13 +116,15 @@ void delete_branch_config (const char *name) /* git config --unset-all remote.foo.push ^\+?refs/heads/bar: */ branch = branch_get(name + 11); - strbuf_addf(&buf, "remote.%s.push", branch->remote_name); - strbuf_addstr(&push_re, "^\\+?"); - strbuf_addstr_escape_re(&push_re, name); - strbuf_addch(&push_re, ':'); - if (git_config_set_multivar(buf.buf, NULL, push_re.buf, 1) < 0) { - warning("Update of config-file failed"); - goto fail; + if (branch->remote_name) { + strbuf_addf(&buf, "remote.%s.push", branch->remote_name); + strbuf_addstr(&push_re, "^\\+?"); + strbuf_addstr_escape_re(&push_re, name); + strbuf_addch(&push_re, ':'); + if (git_config_set_multivar(buf.buf, NULL, push_re.buf, 1) < 0) { + warning("Update of config-file failed"); + goto fail; + } } strbuf_reset(&buf); strbuf_addf(&buf, "branch.%s", name + 11); -- 2.11.4.GIT