git/list[1] front-page[2] threads[3] people[4] search[5] about
 

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] != '/') {
Previous: Johannes Schindelin
Message 6 of 6 in “parse-options: fix parsing of "--foobar=" with no value”
  1. parse-options: fix parsing of "--foobar=" with no valueOlivier Marin, Jul 22, 2008
  2. Sverre RabbelierJul 22, 2008
  3. Pierre HabouzitJul 22, 2008
  4. Olivier MarinJul 22, 2008
  5. Johannes SchindelinJul 22, 2008
  6. Jeff KingJul 22, 2008

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.