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

Re: [PATCH v2] bisect--helper: plug strvec leak

From
Junio C Hamano <gitster@pobox.com>
Date
Oct 11, 2022, 17:11 UTC
Message-ID
<xmqqpmeyuvxt.fsf@gitster.g>
In-Reply-To
<Y0VtkmNwjKcXcemP@coredump.intra.peff.net>
Jeff King <peff@peff.net> writes:
> The bug I'm worried about it is in a human writing the list of strings
> and forgetting the NULL, so there we are losing the (admittedly minor)
> protection.

I expect that this story will repeat itself, especially given that we asserted that it is OK to initialize such an array with variable reference recently in this thread.

Here are a couple that I found with a quick eyeballing of the output of "git grep -e 'run_command_v_opt([^,]*\.v,' \*.c" command.

diff --git a/builtin/clone.c b/builtin/clone.c
index ed8d44bb6a..c93345bc75 100644
--- a/builtin/clone.c
+++ b/builtin/clone.c
@@ -651,9 +651,8 @@ static void update_head(const struct ref *our, const struct ref *remote,
 
 static int git_sparse_checkout_init(const char *repo)
 {
-	struct strvec argv = STRVEC_INIT;
 	int result = 0;
-	strvec_pushl(&argv, "-C", repo, "sparse-checkout", "set", NULL);
+	const char *argv[] = { "-C", repo, "sparse-checkout", "set", NULL };
 
 	/*
 	 * We must apply the setting in the current process
@@ -661,12 +660,11 @@ static int git_sparse_checkout_init(const char *repo)
 	 */
 	core_apply_sparse_checkout = 1;
 
-	if (run_command_v_opt(argv.v, RUN_GIT_CMD)) {
+	if (run_command_v_opt(argv, RUN_GIT_CMD)) {
 		error(_("failed to initialize sparse-checkout"));
 		result = 1;
 	}
 
-	strvec_clear(&argv);
 	return result;
 }
 
diff --git a/builtin/merge.c b/builtin/merge.c
index 0a0ca8b7c4..d261bc652f 100644
--- a/builtin/merge.c
+++ b/builtin/merge.c
@@ -384,24 +384,20 @@ static void reset_hard(const struct object_id *oid, int verbose)
 static void restore_state(const struct object_id *head,
 			  const struct object_id *stash)
 {
-	struct strvec args = STRVEC_INIT;
-
 	reset_hard(head, 1);
 
-	if (is_null_oid(stash))
-		goto refresh_cache;
-
-	strvec_pushl(&args, "stash", "apply", "--index", "--quiet", NULL);
-	strvec_push(&args, oid_to_hex(stash));
+	if (!is_null_oid(stash)) {
+		const char *argv[] = {
+			"stash", "apply", "--index", "--quiet", oid_to_hex(stash), NULL
+		};
 
-	/*
-	 * It is OK to ignore error here, for example when there was
-	 * nothing to restore.
-	 */
-	run_command_v_opt(args.v, RUN_GIT_CMD);
-	strvec_clear(&args);
+		/*
+		 * It is OK to ignore error here, for example when there was
+		 * nothing to restore.
+		 */
+		run_command_v_opt(argv, RUN_GIT_CMD);
+	}
 
-refresh_cache:
 	if (discard_cache() < 0 || read_cache() < 0)
 		die(_("could not read index"));
 }
Previous: Jeff KingNext: Ævar Arnfjörð Bjarmason
Message 14 of 21 in “PATCH] bisect--helper: plug strvec leak in bisect_start()”
  1. René ScharfeOct 4, 2022
  2. Ævar Arnfjörð BjarmasonOct 5, 2022
  3. René ScharfeOct 5, 2022
  4. Junio C HamanoOct 5, 2022
  5. Ævar Arnfjörð BjarmasonOct 6, 2022
  6. Junio C HamanoOct 6, 2022
  7. bisect--helper: plug strvec leakRené Scharfe, Oct 7, 2022
  8. Junio C HamanoOct 7, 2022
  9. Jeff KingOct 11, 2022
  10. Junio C HamanoOct 11, 2022
  11. Ævar Arnfjörð BjarmasonOct 11, 2022
  12. Jeff KingOct 11, 2022
  13. Jeff KingOct 11, 2022
  14. Junio C HamanoOct 11, 2022
  15. Ævar Arnfjörð BjarmasonOct 11, 2022
  16. Junio C HamanoOct 11, 2022
  17. Jeff KingOct 14, 2022
  18. Junio C HamanoOct 14, 2022
  19. René ScharfeOct 15, 2022
  20. Jeff KingOct 15, 2022
  21. Junio C HamanoOct 5, 2022

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.