From: Duy Nguyen <pclouds@gmail.com>
To: Jeff King <peff@peff.net>
Cc: Git Mailing List <git@vger.kernel.org>
Subject: Re: [PATCH 0/3] fix parse-opt string_list leaks
Date: Mon, 13 Jun 2016 16:36:14 +0700 [thread overview]
Message-ID: <CACsJy8CAT54pTotUFKm-piWRppNFz9mjTsnz+5p1+7ykVg60HQ@mail.gmail.com> (raw)
In-Reply-To: <20160613053203.GB3950@sigill.intra.peff.net>
On Mon, Jun 13, 2016 at 12:32 PM, Jeff King <peff@peff.net> wrote:
> On Mon, Jun 13, 2016 at 07:08:55AM +0700, Duy Nguyen wrote:
>
>> > So if we are doing the conservative thing, then I think the resulting
>> > code should either look like:
>> >
>> > if (!v->strdup_strings)
>> > die("BUG: OPT_STRING_LIST should always use strdup_strings");
>> > string_list_append(v, arg);
>>
>> I agree with the analysis. But this die() would hit all callers
>> (except interpret-trailers) because they all initialize with _NODUP
>> and setting strdup_strings may require auditing all access to the
>> string list in question, e.g. to change string_list_append(v,
>> xstrdup(xxx)) to string_list_append(xxx). it may cause side effects if
>> we are not careful.
>
> Yep. It is not really fixing anything, so much as alerting us to broken
> callers. We'd still have to fix the callers. :)
>
>> So far all callers are in builtin/, I think it will not take much time
>> to verify that they all call parse_options() with global argv, then we
>> can just lose extra xstrdup() and stick to string_list_append().
>> OPTION_STRING already assumes that argument strings are stable because
>> they are passed back as-is. Can we go with an easier route, adding a
>> comment on top of parse_options() stating that argv[] pointers may be
>> passed back as-is and it's up to the caller to xstrdup() appropriately
>> before argv[] memory is freed?
>
> Yeah, the two options I laid out were the "conservative" side, where we
> didn't make any assumptions about what is in passed into parse_options.
> But I agree in practice that it's not likely to be a problem to just
> point to the existing strings, and the fact that OPTION_STRING does so
> already makes me even more confident.
>
> So I'd suggest these patches:
>
> [1/3]: parse_opt_string_list: stop allocating new strings
> [2/3]: interpret-trailers: don't duplicate option strings
> [3/3]: blame,shortlog: don't make local option variables static
As usual, it's hard to find things to complain in your patches.
> The first one is what we've been discussing, and the others are just
> follow-on cleanups. I stopped short of a fourth patch to convert more
> cases of:
>
> static struct string_list foo;
>
> to:
>
> static struct string_list foo = STRING_LIST_INIT_NODUP;
>
> The two are equivalent (mostly due to historical reasons). I tend to
> think explicit is better than implicit for something like this (not
> because BSS auto-initialization isn't OK, but because there is an
> explicit choice of dup/nodup that the writer made, and it is good to
> communicate that). But maybe people don't want the extra noise.
I'm on the explicit side. Unless you work a lot with string lists, I
don't think you can remember whether "all zero" initialization is dup
or no dup.
--
Duy
next prev parent reply other threads:[~2016-06-13 9:36 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-06-10 11:57 [PATCH] parse-options-cb.c: use string_list_append_nodup in OPT_STRING_LIST() Nguyễn Thái Ngọc Duy
2016-06-12 22:03 ` Jeff King
2016-06-13 0:08 ` Duy Nguyen
2016-06-13 5:32 ` [PATCH 0/3] fix parse-opt string_list leaks Jeff King
2016-06-13 5:39 ` [PATCH 1/3] parse_opt_string_list: stop allocating new strings Jeff King
2016-06-13 5:39 ` [PATCH 2/3] interpret-trailers: don't duplicate option strings Jeff King
2016-06-13 5:39 ` [PATCH 3/3] blame,shortlog: don't make local option variables static Jeff King
2016-06-14 4:32 ` Eric Sunshine
2016-06-14 5:05 ` Jeff King
2016-08-02 10:52 ` [PATCH] blame: drop strdup of string literal Jeff King
2016-08-03 7:36 ` Eric Sunshine
2016-06-13 9:36 ` Duy Nguyen [this message]
2016-06-13 10:04 ` [PATCH 4/3] use string_list initializer consistently Jeff King
2016-06-13 11:31 ` Duy Nguyen
2016-06-13 17:32 ` Jeff King
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
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CACsJy8CAT54pTotUFKm-piWRppNFz9mjTsnz+5p1+7ykVg60HQ@mail.gmail.com \
--to=pclouds@gmail.com \
--cc=git@vger.kernel.org \
--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.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
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).