From: Derrick Stolee <stolee@gmail.com>
To: Elijah Newren <newren@gmail.com>,
Derrick Stolee via GitGitGadget <gitgitgadget@gmail.com>
Cc: git@vger.kernel.org, gitster@pobox.com,
Taylor Blau <ttaylorr@openai.com>
Subject: Re: [PATCH v2 3/7] trace2: remove use of xstrdup()
Date: Mon, 31 Aug 2026 08:41:44 -0400 [thread overview]
Message-ID: <2eadc838-9d47-442d-a94a-efc570624489@gmail.com> (raw)
In-Reply-To: <CABPp-BH1TeDTeqddZw+cvzou+3PRgw+HNpYF2JnhMTSBp9qfbQ@mail.gmail.com>
On 8/25/2026 6:14 PM, Elijah Newren wrote:
> On Tue, Aug 25, 2026 at 11:58 AM Derrick Stolee via GitGitGadget
> <gitgitgadget@gmail.com> wrote:
>>
> [...]
>> For full defense in depth, we remove the xstrdup() calls from
>> trace2/tr2_sysenv.c.
>>
>> First, in tr2_sysenv_cb(), we need to handle a failed assignment of the
>> value with a negative return to halt the config parsing loop.
>>
> [...]
>> --- a/trace2/tr2_sysenv.c
>> +++ b/trace2/tr2_sysenv.c
>> @@ -74,7 +74,9 @@ static int tr2_sysenv_cb(const char *key, const char *value,
>> if (!value)
>> return config_error_nonbool(key);
>> free(tr2_sysenv_settings[k].value);
>> - tr2_sysenv_settings[k].value = xstrdup(value);
>> + tr2_sysenv_settings[k].value = strdup(value);
>> + if (!tr2_sysenv_settings[k].value)
>> + return -1;
>
> I'm not sure if this matters, but I think the call sequence from
> config.c to this function is:
>
> read_very_early_config ->
> config_with_options ->
> git_config_from_file_with_options ->
> do_config_from_file ->
> do_config_from ->
> git_parse_source ->
> get_value ->
> git_config_include ->
> tr2_sysenv_cb
>
> and the -1 unwinds back to git_parse_source, which breaks, formats an
> error message, and calls die:
>
> error_msg = xstrfmt(_("bad config line %d in file %s")...)
> die("%s", error_msg)
Thanks for the careful read! It's particularly important that we
don't suggest that the config value is bad because we couldn't
allocate memory.
> Am I reading this right? If so, the -1 actually triggers a die as
> well -- unless the allocation in xstrfmt manages to kill it first.
> This isn't a regression (the old xstrdup() also died) and the die
> isn't inside the trace functions, but the commit message might read as
> promising more than it delivers.
Yes, I believe you are correct. We should return 0 to terminate
early without a failure.
That said, I think that the die() in the config code will remain a
"safe" place to die(), as we won't re-trigger this config-parsing
code during any tracing of that die() message. But it's best to be
safe and have the tracing continue to be "best effort" when system
calls fail.
Thanks,
-Stolee
next prev parent reply other threads:[~2026-08-31 12:41 UTC|newest]
Thread overview: 42+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-15 16:12 [PATCH] trace2: tolerate failed timestamp formatting Derrick Stolee via GitGitGadget
2026-07-17 16:24 ` Taylor Blau
2026-07-18 15:01 ` Derrick Stolee
2026-07-20 14:29 ` Junio C Hamano
2026-07-20 14:37 ` Taylor Blau
2026-07-29 21:35 ` Junio C Hamano
2026-07-31 13:26 ` Derrick Stolee
2026-07-31 15:57 ` Junio C Hamano
2026-08-25 18:56 ` [PATCH v2 0/7] trace2: stop allowing die() Derrick Stolee via GitGitGadget
2026-08-25 18:56 ` [PATCH v2 1/7] banned-die: create header for banning of functions Derrick Stolee via GitGitGadget
2026-08-25 20:34 ` Junio C Hamano
2026-08-31 12:28 ` Derrick Stolee
2026-08-31 13:30 ` Patrick Steinhardt
2026-08-25 22:14 ` Elijah Newren
2026-08-31 12:29 ` Derrick Stolee
2026-08-27 5:10 ` Jeff King
2026-08-31 12:38 ` Derrick Stolee
2026-08-25 18:56 ` [PATCH v2 2/7] trace2: tolerate failed timestamp formatting Derrick Stolee via GitGitGadget
2026-08-25 18:56 ` [PATCH v2 3/7] trace2: remove use of xstrdup() Derrick Stolee via GitGitGadget
2026-08-25 22:14 ` Elijah Newren
2026-08-31 12:41 ` Derrick Stolee [this message]
2026-08-25 18:56 ` [PATCH v2 4/7] trace2: remove use of ALLOC_ARRAY() Derrick Stolee via GitGitGadget
2026-08-25 18:56 ` [PATCH v2 5/7] trace2: remove use of xstrfmt() Derrick Stolee via GitGitGadget
2026-08-25 22:14 ` Elijah Newren
2026-08-25 22:36 ` Junio C Hamano
2026-08-31 12:51 ` Derrick Stolee
2026-08-25 18:56 ` [PATCH v2 6/7] trace2: remove use of ALLOC_GROW() Derrick Stolee via GitGitGadget
2026-08-25 22:14 ` Elijah Newren
2026-08-25 18:56 ` [PATCH v2 7/7] trace2: remove use of xcalloc() Derrick Stolee via GitGitGadget
2026-08-27 5:23 ` [PATCH v2 0/7] trace2: stop allowing die() Jeff King
2026-08-31 13:27 ` Derrick Stolee
2026-09-01 5:01 ` Jeff King
2026-09-01 5:03 ` Jeff King
2026-09-01 13:42 ` Derrick Stolee
2026-08-31 17:25 ` [PATCH v3 " Derrick Stolee via GitGitGadget
2026-08-31 17:25 ` [PATCH v3 1/7] banned-die: create header for banning of functions Derrick Stolee via GitGitGadget
2026-08-31 17:25 ` [PATCH v3 2/7] trace2: tolerate failed timestamp formatting Derrick Stolee via GitGitGadget
2026-08-31 17:25 ` [PATCH v3 3/7] trace2: remove use of xstrdup() Derrick Stolee via GitGitGadget
2026-08-31 17:25 ` [PATCH v3 4/7] trace2: remove use of ALLOC_ARRAY() Derrick Stolee via GitGitGadget
2026-08-31 17:25 ` [PATCH v3 5/7] trace2: remove use of xstrfmt() Derrick Stolee via GitGitGadget
2026-08-31 17:25 ` [PATCH v3 6/7] trace2: remove use of ALLOC_GROW() Derrick Stolee via GitGitGadget
2026-08-31 17:25 ` [PATCH v3 7/7] trace2: remove use of xcalloc() Derrick Stolee via GitGitGadget
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=2eadc838-9d47-442d-a94a-efc570624489@gmail.com \
--to=stolee@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitgitgadget@gmail.com \
--cc=gitster@pobox.com \
--cc=newren@gmail.com \
--cc=ttaylorr@openai.com \
/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