From: "Derrick Stolee via GitGitGadget" <gitgitgadget@gmail.com>
To: git@vger.kernel.org
Cc: gitster@pobox.com, Taylor Blau <ttaylorr@openai.com>,
Elijah Newren <newren@gmail.com>, Jeff King <peff@peff.net>,
Derrick Stolee <stolee@gmail.com>,
Derrick Stolee <stolee@gmail.com>
Subject: [PATCH v3 4/7] trace2: remove use of ALLOC_ARRAY()
Date: Mon, 31 Aug 2026 17:25:40 +0000 [thread overview]
Message-ID: <5bf6ab91f37cd80dba5e50eee85f9f3258f34be3.1788197143.git.gitgitgadget@gmail.com> (raw)
In-Reply-To: <pull.2178.v3.git.1788197143.gitgitgadget@gmail.com>
From: Derrick Stolee <stolee@gmail.com>
The banned-die.h header is used to prevent use of helper methods that
call die(). Remove use of the ALLOC_ARRAY() helper, which calls die() on
allocation failures. Replace the use in trace2.c with a more direct
allocation and soft failure when allocation fails. This prevents die()
recursion loops when memory allocation fails and trace2 logs are
enabled.
The tricky part about this change is how to handle the results from
redact_arg(), which is a 'const char *' result because it might be a
pointer directly to the externally-controlled argument. When it is
different from the argument, then it is indeed a newly-allocated string
that we need to free before returning. This requires using a (char *)
cast to allow a change.
Signed-off-by: Derrick Stolee <stolee@gmail.com>
---
banned-die.h | 3 +++
trace2.c | 16 ++++++++++++++--
2 files changed, 17 insertions(+), 2 deletions(-)
diff --git a/banned-die.h b/banned-die.h
index bf16ec5ba9..0ad9a6c492 100644
--- a/banned-die.h
+++ b/banned-die.h
@@ -17,4 +17,7 @@
#undef xstrdup
#define xstrdup(str) BANNED(xstrdup)
+#undef ALLOC_ARRAY
+#define ALLOC_ARRAY(x, alloc) BANNED(ALLOC_ARRAY)
+
#endif /* BANNED_DIE_H */
diff --git a/trace2.c b/trace2.c
index 8c974dee87..ea021c602e 100644
--- a/trace2.c
+++ b/trace2.c
@@ -305,7 +305,11 @@ static const char **redact_argv(const char **argv)
for (j = 0; argv[j]; j++)
; /* keep counting */
- ALLOC_ARRAY(ret, j + 1);
+ ret = calloc(j + 1, sizeof(*ret));
+ if (!ret) {
+ free((char *)redacted);
+ return NULL;
+ }
ret[j] = NULL;
for (j = 0; j < i; j++)
@@ -346,6 +350,8 @@ void trace2_cmd_start_fl(const char *file, int line, const char **argv)
us_elapsed_absolute = tr2tls_absolute_elapsed(us_now);
redacted = redact_argv(argv);
+ if (!redacted)
+ return;
for_each_wanted_builtin (j, tgt_j)
if (tgt_j->pfn_start_fl)
@@ -514,6 +520,7 @@ void trace2_child_start_fl(const char *file, int line,
uint64_t us_now;
uint64_t us_elapsed_absolute;
const char **orig_argv = cmd->args.v;
+ const char **redacted;
if (!trace2_enabled)
return;
@@ -531,7 +538,10 @@ void trace2_child_start_fl(const char *file, int line,
* temporarily replace the original argv (inside the `strvec`)
* with a possibly redacted version.
*/
- cmd->args.v = redact_argv(orig_argv);
+ redacted = redact_argv(orig_argv);
+ if (!redacted)
+ return;
+ cmd->args.v = redacted;
for_each_wanted_builtin (j, tgt_j)
if (tgt_j->pfn_child_start_fl)
@@ -623,6 +633,8 @@ int trace2_exec_fl(const char *file, int line, const char *exe,
exec_id = tr2tls_locked_increment(&tr2_next_exec_id);
redacted = redact_argv(argv);
+ if (!redacted)
+ return exec_id;
for_each_wanted_builtin (j, tgt_j)
if (tgt_j->pfn_exec_fl)
--
gitgitgadget
next prev parent reply other threads:[~2026-08-31 17:25 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
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 ` Derrick Stolee via GitGitGadget [this message]
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=5bf6ab91f37cd80dba5e50eee85f9f3258f34be3.1788197143.git.gitgitgadget@gmail.com \
--to=gitgitgadget@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=newren@gmail.com \
--cc=peff@peff.net \
--cc=stolee@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