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

Re: [PATCH] Support running an arbitrary git action through checkout

From
Jeff King <peff@peff.net>
Date
May 10, 2013, 17:00 UTC
Message-ID
<20130510170016.GA29848@sigill.intra.peff.net>
In-Reply-To
<2d5cfb3be9487f607051cad3d5230434660307ba.1368198269.git.trast@inf.ethz.ch>
On Fri, May 10, 2013 at 05:06:07PM +0200, Thomas Rast wrote:
Show 15 quoted lines
> +	if (argc > 1 && !prefixcmp(argv[1], "--")) {
> +		const char *subcommand = argv[1] + 2;
> +		struct cmdnames main_cmds, other_cmds;
> +
> +		memset(&main_cmds, 0, sizeof(main_cmds));
> +		memset(&other_cmds, 0, sizeof(other_cmds));
> +
> +		load_command_list("git-", &main_cmds, &other_cmds);
> +
> +		if (is_in_cmdlist(&main_cmds, subcommand) ||
> +		    is_in_cmdlist(&other_cmds, subcommand)) {
> +			const char **args = xmalloc((argc) * sizeof(char*));
> +			args[0] = subcommand;
> +			memcpy(args+1, argv+2, argc*sizeof(char*));
> +			args[argc] = NULL;

Doesn't this memcpy overflow args, since it is only argc slots long? I think you want to copy only (argc-1) slots, since you are omitting both argv[0] as well as the "--subcommand" argument in argv[1]. You can also drop the setting of NULL, as you will copy the original NULL as the last item in your memcpy.

Other than that, the patch looks brilliant. :)
-Peff
Previous: Ramkumar Ramachandra
Message 4 of 4 in “Support running an arbitrary git action through checkout”
  1. Support running an arbitrary git action through checkoutThomas Rast, May 10, 2013
  2. Junio C HamanoMay 10, 2013
  3. Ramkumar RamachandraMay 10, 2013
  4. Jeff KingMay 10, 2013

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.