{"thread":{"id":"20138","subject":"[PATCH next] branch.c: if remote is not config'd for branch, don't try delete push config","startedAt":"2009-07-16T21:26:15Z","lastAt":"2009-07-17T22:04:04Z","messageCount":2,"participants":["Brandon Casey","Jeff King"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"118140","messageId":"W0GiRm9n1NEO0ox1puhqZPKGDpWW0rbH6Cp2gxr7ofSuhyo4HCl88lyU5dRIkYdZUK1rEnxQExw@cipher.nrlssc.navy.mil","threadId":"20138","inReplyTo":null,"subject":"[PATCH next] branch.c: if remote is not config'd for branch, don't try delete push config","fromName":"Brandon Casey","fromEmail":"casey@nrlssc.navy.mil","sentAt":"2009-07-16T21:26:15Z","receivedAt":"2009-07-16T21:26:15Z","isPatch":true,"sender":{"key":"drafnel@gmail.com","avatar":"https://avatars.githubusercontent.com/u/921167?v=4"},"body":"From: Brandon Casey <drafnel@gmail.com>\n\nIf a remote is not configured for the branch configuration being deleted,\nthen don't try to delete the remote.<remote>.push configuration for the\nbranch.  When the remote is not configured, branch->remote_name is not\nfilled in.  When this NULL branch->remote_name is passed to strbuf_addf()\nit will result in an attempt to remove a bogus configuration statement in\nthe best case (i.e. \"remote.(null).push\" for platforms which guard against\nsupplying NULL to a %s conversion spec) and a segfault in the worst case.\n\nSo check whether branch->remote_name is non-NULL before trying to use it.\n\nSigned-off-by: Brandon Casey <drafnel@gmail.com>\n---\n branch.c |   17 ++++++++++-------\n 1 files changed, 10 insertions(+), 7 deletions(-)\n\ndiff --git a/branch.c b/branch.c\nindex dfde568..6dc9175 100644\n--- a/branch.c\n+++ b/branch.c\n@@ -116,13 +116,16 @@ void delete_branch_config (const char *name)\n \n \t/* git config --unset-all remote.foo.push ^\\+?refs/heads/bar:  */\n \tbranch = branch_get(name + 11);\n-\tstrbuf_addf(&buf, \"remote.%s.push\", branch->remote_name);\n-\tstrbuf_addstr(&push_re, \"^\\\\+?\");\n-\tstrbuf_addstr_escape_re(&push_re, name);\n-\tstrbuf_addch(&push_re, ':');\n-\tif (git_config_set_multivar(buf.buf, NULL, push_re.buf, 1) < 0) {\n-\t\twarning(\"Update of config-file failed\");\n-\t\tgoto fail;\n+\tif (branch->remote_name) {\n+\t\tstrbuf_addf(&buf, \"remote.%s.push\", branch->remote_name);\n+\t\tstrbuf_addstr(&push_re, \"^\\\\+?\");\n+\t\tstrbuf_addstr_escape_re(&push_re, name);\n+\t\tstrbuf_addch(&push_re, ':');\n+\t\tif (git_config_set_multivar(buf.buf, NULL, push_re.buf, 1) < 0)\n+\t\t{\n+\t\t\twarning(\"Update of config-file failed\");\n+\t\t\tgoto fail;\n+\t\t}\n \t}\n \tstrbuf_reset(&buf);\n \tstrbuf_addf(&buf, \"branch.%s\", name + 11);\n-- \n1.6.3.1.24.g152f4\n"},{"id":"118204","messageId":"20090717220404.GA32214@coredump.intra.peff.net","threadId":"20138","inReplyTo":"W0GiRm9n1NEO0ox1puhqZPKGDpWW0rbH6Cp2gxr7ofSuhyo4HCl88lyU5dRIkYdZUK1rEnxQExw@cipher.nrlssc.navy.mil","subject":"Re: [PATCH next] branch.c: if remote is not config'd for branch, don't try delete push config","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2009-07-17T22:04:04Z","receivedAt":"2009-07-17T22:04:04Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Thu, Jul 16, 2009 at 04:26:15PM -0500, Brandon Casey wrote:\n\n> So check whether branch->remote_name is non-NULL before trying to use it.\n\nThanks, my Solaris autobuild detected this last night. I bisected it to\n4f67cc0, and I can confirm that your patch fixes it.\n\n-Peff\n"}]}