Skip to content

Commit

Permalink
trace2: prevent segfault on config collection where no value specified
Browse files Browse the repository at this point in the history
When TRACE2 analytics is enabled, a git config option that has no value
causes a segfault.

Steps to Reproduce
GIT_TRACE2=true GIT_TRACE2_CONFIG_PARAMS=status.*
git -c status.relativePaths version
Expected Result
git version 2.46.0
Actual Result
zsh: segmentation fault GIT_TRACE2=true

This adds checks to prevent the segfault and instead return
an empty value.

Signed-off-by: Adam Murray <ad@canva.com>
  • Loading branch information
ad-murray committed Jan 8, 2025
1 parent 8f8d6ee commit 0a03293
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 6 deletions.
8 changes: 8 additions & 0 deletions t/t0210-trace2-normal.sh
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,14 @@ test_expect_success 'bug messages followed by BUG() are written to trace2' '
test_cmp expect actual
'

test_expect_success 'empty configuration values are handled' '
test_when_finished "rm trace2.normal actual expect" &&
echo >expect &&
GIT_TRACE2="$(pwd)/trace2.normal" GIT_TRACE2_CONFIG_PARAMS=foo.empty \
git -c foo.empty config foo.empty >actual &&
test_cmp expect actual
'

sane_unset GIT_TRACE2_BRIEF

# Now test without environment variables and get all Trace2 settings
Expand Down
2 changes: 1 addition & 1 deletion trace2.c
Original file line number Diff line number Diff line change
Expand Up @@ -762,7 +762,7 @@ void trace2_def_param_fl(const char *file, int line, const char *param,
if (!trace2_enabled)
return;

redacted = redact_arg(value);
redacted = value ? redact_arg(value): NULL;

for_each_wanted_builtin (j, tgt_j)
if (tgt_j->pfn_param_fl)
Expand Down
3 changes: 2 additions & 1 deletion trace2/tr2_tgt_event.c
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,8 @@ static void fn_param_fl(const char *file, int line, const char *param,
event_fmt_prepare(event_name, file, line, NULL, &jw);
jw_object_string(&jw, "scope", scope_name);
jw_object_string(&jw, "param", param);
jw_object_string(&jw, "value", value);
if (value)
jw_object_string(&jw, "value", value);
jw_end(&jw);

tr2_dst_write_line(&tr2dst_event, &jw.json);
Expand Down
5 changes: 3 additions & 2 deletions trace2/tr2_tgt_normal.c
Original file line number Diff line number Diff line change
Expand Up @@ -307,8 +307,9 @@ static void fn_param_fl(const char *file, int line, const char *param,
enum config_scope scope = kvi->scope;
const char *scope_name = config_scope_name(scope);

strbuf_addf(&buf_payload, "def_param scope:%s %s=%s", scope_name, param,
value);
strbuf_addf(&buf_payload, "def_param scope:%s %s", scope_name, param);
if (value)
strbuf_addf(&buf_payload, "=%s", value);
normal_io_write_fl(file, line, &buf_payload);
strbuf_release(&buf_payload);
}
Expand Down
5 changes: 3 additions & 2 deletions trace2/tr2_tgt_perf.c
Original file line number Diff line number Diff line change
Expand Up @@ -446,8 +446,9 @@ static void fn_param_fl(const char *file, int line, const char *param,
struct strbuf scope_payload = STRBUF_INIT;
enum config_scope scope = kvi->scope;
const char *scope_name = config_scope_name(scope);

strbuf_addf(&buf_payload, "%s:%s", param, value);
strbuf_addf(&buf_payload, param);
if (value)
strbuf_addf(&buf_payload, ":%s", value);

Check failure on line 451 in trace2/tr2_tgt_perf.c

View workflow job for this annotation

GitHub Actions / fuzz smoke test

trace2/tr2_tgt_perf.c:451:28: format string is not a string literal (potentially insecure) [-Werror,-Wformat-security]

Check failure on line 451 in trace2/tr2_tgt_perf.c

View workflow job for this annotation

GitHub Actions / linux-reftable-leaks (ubuntu-latest)

trace2/tr2_tgt_perf.c:451:9: format not a string literal and no format arguments [-Werror=format-security]

Check failure on line 451 in trace2/tr2_tgt_perf.c

View workflow job for this annotation

GitHub Actions / linux-gcc (ubuntu-20.04)

trace2/tr2_tgt_perf.c:451:2: format not a string literal and no format arguments [-Werror=format-security]

Check failure on line 451 in trace2/tr2_tgt_perf.c

View workflow job for this annotation

GitHub Actions / linux-leaks (ubuntu-latest)

trace2/tr2_tgt_perf.c:451:9: format not a string literal and no format arguments [-Werror=format-security]

Check failure on line 451 in trace2/tr2_tgt_perf.c

View workflow job for this annotation

GitHub Actions / linux-TEST-vars (ubuntu-20.04)

trace2/tr2_tgt_perf.c:451:2: format not a string literal and no format arguments [-Werror=format-security]

Check failure on line 451 in trace2/tr2_tgt_perf.c

View workflow job for this annotation

GitHub Actions / linux-musl (alpine)

trace2/tr2_tgt_perf.c:451:9: format not a string literal and no format arguments [-Werror=format-security]

Check failure on line 451 in trace2/tr2_tgt_perf.c

View workflow job for this annotation

GitHub Actions / debian-11 (debian:11)

trace2/tr2_tgt_perf.c:451:2: format not a string literal and no format arguments [-Werror=format-security]

Check failure on line 451 in trace2/tr2_tgt_perf.c

View workflow job for this annotation

GitHub Actions / linux-sha256 (ubuntu-latest)

trace2/tr2_tgt_perf.c:451:28: format string is not a string literal (potentially insecure) [-Werror,-Wformat-security]

Check failure on line 451 in trace2/tr2_tgt_perf.c

View workflow job for this annotation

GitHub Actions / linux-gcc-default (ubuntu-latest)

trace2/tr2_tgt_perf.c:451:9: format not a string literal and no format arguments [-Werror=format-security]

Check failure on line 451 in trace2/tr2_tgt_perf.c

View workflow job for this annotation

GitHub Actions / almalinux-8 (almalinux:8)

trace2/tr2_tgt_perf.c:451:2: format not a string literal and no format arguments [-Werror=format-security]

Check failure on line 451 in trace2/tr2_tgt_perf.c

View workflow job for this annotation

GitHub Actions / linux-asan-ubsan (ubuntu-latest)

trace2/tr2_tgt_perf.c:451:28: format string is not a string literal (potentially insecure) [-Werror,-Wformat-security]

Check failure on line 451 in trace2/tr2_tgt_perf.c

View workflow job for this annotation

GitHub Actions / linux-reftable (ubuntu-latest)

trace2/tr2_tgt_perf.c:451:28: format string is not a string literal (potentially insecure) [-Werror,-Wformat-security]

Check failure on line 451 in trace2/tr2_tgt_perf.c

View workflow job for this annotation

GitHub Actions / pedantic (fedora)

trace2/tr2_tgt_perf.c:451:9: format not a string literal and no format arguments [-Werror=format-security]

Check failure on line 451 in trace2/tr2_tgt_perf.c

View workflow job for this annotation

GitHub Actions / linux32 (i386/ubuntu:focal)

trace2/tr2_tgt_perf.c:451:2: format not a string literal and no format arguments [-Werror=format-security]

Check failure on line 451 in trace2/tr2_tgt_perf.c

View workflow job for this annotation

GitHub Actions / win build

trace2/tr2_tgt_perf.c:451:9: format not a string literal and no format arguments [-Werror=format-security]
strbuf_addf(&scope_payload, "%s:%s", "scope", scope_name);

perf_io_write_fl(file, line, event_name, NULL, NULL, NULL,
Expand Down

0 comments on commit 0a03293

Please sign in to comment.