Git Mailing List Archive mirror
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: "Ævar Arnfjörð Bjarmason" <avarab@gmail.com>
Cc: "Jeff King" <peff@peff.net>, "René Scharfe" <l.s.r@web.de>,
	"Git List" <git@vger.kernel.org>
Subject: Re: [PATCH v2] bisect--helper: plug strvec leak
Date: Tue, 11 Oct 2022 14:43:24 -0700	[thread overview]
Message-ID: <xmqq8rlmujcz.fsf@gitster.g> (raw)
In-Reply-To: <221011.86czayns5x.gmgdl@evledraar.gmail.com> ("Ævar Arnfjörð Bjarmason"'s message of "Tue, 11 Oct 2022 20:13:20 +0200")

Æ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...

  reply	other threads:[~2022-10-11 21:43 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-04 16:06 PATCH] bisect--helper: plug strvec leak in bisect_start() René Scharfe
2022-10-05  7:29 ` Ævar Arnfjörð Bjarmason
2022-10-05 15:43   ` René Scharfe
2022-10-05 19:44   ` Junio C Hamano
2022-10-06 21:35     ` Ævar Arnfjörð Bjarmason
2022-10-06 21:53       ` Junio C Hamano
2022-10-07 15:08         ` [PATCH v2] bisect--helper: plug strvec leak René Scharfe
2022-10-07 17:21           ` Junio C Hamano
2022-10-11  2:39           ` Jeff King
2022-10-11  5:42             ` Junio C Hamano
2022-10-11  7:29               ` Ævar Arnfjörð Bjarmason
2022-10-11 13:21                 ` Jeff King
2022-10-11 13:20               ` Jeff King
2022-10-11 17:11                 ` Junio C Hamano
2022-10-11 18:13                   ` Ævar Arnfjörð Bjarmason
2022-10-11 21:43                     ` Junio C Hamano [this message]
2022-10-14 19:44                       ` Jeff King
2022-10-14 20:23                         ` Junio C Hamano
2022-10-15  6:51                         ` René Scharfe
2022-10-15 18:21                           ` Jeff King
2022-10-05 19:41 ` PATCH] bisect--helper: plug strvec leak in bisect_start() Junio C Hamano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=xmqq8rlmujcz.fsf@gitster.g \
    --to=gitster@pobox.com \
    --cc=avarab@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=l.s.r@web.de \
    --cc=peff@peff.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).