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 5/7] trace2: remove use of xstrfmt()
Date: Mon, 31 Aug 2026 17:25:41 +0000 [thread overview]
Message-ID: <3e419c55225f452f9472eac2cfb82aadb680a41e.1788197143.git.gitgitgadget@gmail.com> (raw)
In-Reply-To: <pull.2178.v3.git.1788197143.gitgitgadget@gmail.com>
From: Derrick Stolee <stolee@gmail.com>
We continue removing the possibility of a die() in the trace2 API by
banning xstrfmt(), which calls die() during a failure to format. Instead
of allowing a die(), perform a soft failure by failing to output the
trace2 data when such a failure occurs.
This requires carefully concatenating strings using memcpy() to
construct redacted data to avoid copying password information in traced
URLs.
Update t0212 to more carefully test this behavior to explicitly include
the ":<REDACTED>" string in the appropriate context.
Helped-by: Elijah Newren <newren@gmail.com>
Signed-off-by: Derrick Stolee <stolee@gmail.com>
---
banned-die.h | 3 +++
t/t0212-trace2-event.sh | 12 ++++++++----
trace2.c | 34 ++++++++++++++++++++++++++++++++--
3 files changed, 43 insertions(+), 6 deletions(-)
diff --git a/banned-die.h b/banned-die.h
index 0ad9a6c492..4d1800353d 100644
--- a/banned-die.h
+++ b/banned-die.h
@@ -17,6 +17,9 @@
#undef xstrdup
#define xstrdup(str) BANNED(xstrdup)
+#undef xstrfmt
+#define xstrfmt(...) BANNED(xstrfmt)
+
#undef ALLOC_ARRAY
#define ALLOC_ARRAY(x, alloc) BANNED(ALLOC_ARRAY)
diff --git a/t/t0212-trace2-event.sh b/t/t0212-trace2-event.sh
index f5358a1dd4..23df800395 100755
--- a/t/t0212-trace2-event.sh
+++ b/t/t0212-trace2-event.sh
@@ -332,7 +332,8 @@ test_expect_success 'unsafe URLs are redacted by default in cmd_start events' '
GIT_TRACE2_EVENT="$(pwd)/trace.event" \
test-tool trace2 300redact_start git clone https://user:pwd@example.com/ clone2 &&
- test_grep ! user:pwd trace.event
+ test_grep ! user:pwd trace.event &&
+ test_grep "user:<REDACTED>@example.com/" trace.event
'
test_expect_success 'unsafe URLs are redacted by default in child_start events' '
@@ -341,7 +342,8 @@ test_expect_success 'unsafe URLs are redacted by default in child_start events'
GIT_TRACE2_EVENT="$(pwd)/trace.event" \
test-tool trace2 301redact_child_start git clone https://user:pwd@example.com/ clone2 &&
- test_grep ! user:pwd trace.event
+ test_grep ! user:pwd trace.event &&
+ test_grep "user:<REDACTED>@example.com/" trace.event
'
test_expect_success 'unsafe URLs are redacted by default in exec events' '
@@ -350,7 +352,8 @@ test_expect_success 'unsafe URLs are redacted by default in exec events' '
GIT_TRACE2_EVENT="$(pwd)/trace.event" \
test-tool trace2 302redact_exec git clone https://user:pwd@example.com/ clone2 &&
- test_grep ! user:pwd trace.event
+ test_grep ! user:pwd trace.event &&
+ test_grep "user:<REDACTED>@example.com/" trace.event
'
test_expect_success 'unsafe URLs are redacted by default in def_param events' '
@@ -359,7 +362,8 @@ test_expect_success 'unsafe URLs are redacted by default in def_param events' '
GIT_TRACE2_EVENT="$(pwd)/trace.event" \
test-tool trace2 303redact_def_param url https://user:pwd@example.com/ &&
- test_grep ! user:pwd trace.event
+ test_grep ! user:pwd trace.event &&
+ test_grep "user:<REDACTED>@example.com/" trace.event
'
test_done
diff --git a/trace2.c b/trace2.c
index ea021c602e..4a597d8213 100644
--- a/trace2.c
+++ b/trace2.c
@@ -261,7 +261,10 @@ int trace2_is_enabled(void)
static const char *redact_arg(const char *arg)
{
const char *p, *colon;
+ const char *redact = ":<REDACTED>";
+ char *redacted;
size_t at;
+ size_t prefix_len, suffix_len, redacted_len, redact_len;
if (!trace2_redact ||
(!skip_prefix(arg, "https://", &p) &&
@@ -276,7 +279,25 @@ static const char *redact_arg(const char *arg)
if (!colon)
return arg;
- return xstrfmt("%.*s:<REDACTED>%s", (int)(colon - arg), arg, p + at);
+ redact_len = strlen(redact);
+ prefix_len = colon - arg;
+ suffix_len = strlen(p + at);
+
+ if (unsigned_add_overflows(prefix_len, suffix_len) ||
+ unsigned_add_overflows(prefix_len + suffix_len, redact_len) ||
+ unsigned_add_overflows(prefix_len + suffix_len + redact_len, 1))
+ return NULL;
+
+ redacted_len = prefix_len + suffix_len + redact_len + 1;
+
+ redacted = malloc(redacted_len);
+ if (!redacted)
+ return NULL;
+
+ memcpy(redacted, arg, prefix_len);
+ memcpy(redacted + prefix_len, redact, redact_len);
+ memcpy(redacted + prefix_len + redact_len, p + at, suffix_len + 1);
+ return redacted;
}
/*
@@ -301,6 +322,8 @@ static const char **redact_argv(const char **argv)
if (!argv[i])
return argv;
+ if (!redacted)
+ return NULL;
for (j = 0; argv[j]; j++)
; /* keep counting */
@@ -317,7 +340,14 @@ static const char **redact_argv(const char **argv)
ret[i] = redacted;
for (++i; argv[i]; i++) {
redacted = redact_arg(argv[i]);
- ret[i] = redacted ? redacted : argv[i];
+ if (!redacted) {
+ for (j = 0; j < i; j++)
+ if (ret[j] != argv[j])
+ free((void *)ret[j]);
+ free(ret);
+ return NULL;
+ }
+ ret[i] = redacted;
}
return ret;
--
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 ` [PATCH v3 4/7] trace2: remove use of ALLOC_ARRAY() Derrick Stolee via GitGitGadget
2026-08-31 17:25 ` Derrick Stolee via GitGitGadget [this message]
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=3e419c55225f452f9472eac2cfb82aadb680a41e.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;
as well as URLs for NNTP newsgroup(s).