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, 21:43 UTC
Message-ID
<xmqq8rlmujcz.fsf@gitster.g>
In-Reply-To
<221011.86czayns5x.gmgdl@evledraar.gmail.com>
Ævar Arnfjörð Bjarmason <avarab@gmail.com> writes:
> I was experimenting with implementing a run_command_opt_l() earlier
> which would give us the safety Jeff notes. The relevant end-state for
> these two files is (there's more conversions, and I manually edited the
> diff to remove an unrelated change):

There still are some changes that would not belong here, but for the purpose of illustrating the usage of _l variant, this is good enough. Of course, if we want to follow the existing naming scheme, the new function must be called _l_opt(), not _opt_l(). _v_ in the _v_opt() comes from execv() and you are adding execl() analogue here.

> -	if (run_command_v_opt(argv.v, RUN_GIT_CMD)) {
> +	if (run_command_opt_l(RUN_GIT_CMD, "-C", repo, "sparse-checkout",
> +			      "set", NULL)) {

And this does give us protection from the "Programmers can give unterminated list to run_command_v_opt() by mistake", which is not really solved mechanically even if the list is prepared with the strvec API (because the compiler has to be smart enough to know that argv.v was prepared with proper use of the API), which is nice.

Having to give the option flags as the first argument, of course it is necessary because we are talking about the _l variant with varargs, looks ugly, though.

Also, I am not sure how useful this new function actually is. Many hits from my quick "grep" in the message you are responding to did use strvec because they wanted to dynamically build up the command line, and _l variant does not really shine in these places.

We may probably be able to refactor some (but not all) of these sites so that the command line is not built dynamically with unknown number of elements in unknown order, but that feels like a solution looking for a problem, changing code to use the new function, tail wagging the dog. So, I dunno...

Previous: Ævar Arnfjörð BjarmasonNext: Jeff King
Message 16 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.