Skip to content

Commit

Permalink
When TRACE2 analytics is enabled, a git config option that has no value
Browse files Browse the repository at this point in the history
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 7, 2025
1 parent 24ba9db commit 12a521e
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 6 deletions.
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 || !value)
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, "%s", param);
if (value)
strbuf_addf(&buf_payload, ":%s", value);
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 12a521e

Please sign in to comment.