Re: [PATCH] parse-options: fix parsing of "--foobar=" with no value
- From
Jeff King <peff@peff.net>
- Date
- Jul 22, 2008, 20:09 UTC
- Message-ID
- <20080722200911.GA3097@sigill.intra.peff.net>
- In-Reply-To
- <48863436.50309@free.fr>
On Tue, Jul 22, 2008 at 09:25:42PM +0200, Olivier Marin wrote:
Show 8 quoted lines
> I found the "random bug" while migrating "git init" to parse-options. I > think you can reproduce it with: > > $ git clone --template= <repo> > error: ignoring template /var/run/synaptic.socket > fatal: cannot opendir /var/run/sudo > > But now, it appears the problem is not in parse-options, sorry.
Yes, the problem is that copy_templates in builtin-init-db.c is totally broken for an empty template name. It writes past the beginning of the string, and then starts copying at "/". Oops.
Maybe something like this is better? It should define --template= to mean "don't copy any templates" (and I haven't tested it at all).
diff --git a/builtin-init-db.c b/builtin-init-db.c index 38b4fcb..baf0d09 100644 --- a/builtin-init-db.c +++ b/builtin-init-db.c @@ -117,6 +117,8 @@ static void copy_templates(const char *template_dir) template_dir = getenv(TEMPLATE_DIR_ENVIRONMENT); if (!template_dir) template_dir = system_path(DEFAULT_GIT_TEMPLATE_DIR); + if (!template_dir[0]) + return; strcpy(template_path, template_dir); template_len = strlen(template_path); if (template_path[template_len-1] != '/') {