Skip to content

Commit 627d9b5

Browse files
committed
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>
1 parent 8f8d6ee commit 627d9b5

File tree

5 files changed

+18
-7
lines changed

5 files changed

+18
-7
lines changed

t/t0210-trace2-normal.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,14 @@ test_expect_success 'bug messages followed by BUG() are written to trace2' '
244244
test_cmp expect actual
245245
'
246246

247+
test_expect_success 'empty configuration values are handled' '
248+
test_when_finished "rm trace2.normal actual expect" &&
249+
echo >expect &&
250+
GIT_TRACE2="$(pwd)/trace2.normal" GIT_TRACE2_CONFIG_PARAMS=foo.empty \
251+
git -c foo.empty config foo.empty >actual &&
252+
test_cmp expect actual
253+
'
254+
247255
sane_unset GIT_TRACE2_BRIEF
248256

249257
# Now test without environment variables and get all Trace2 settings

trace2.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -759,10 +759,10 @@ void trace2_def_param_fl(const char *file, int line, const char *param,
759759
int j;
760760
const char *redacted;
761761

762-
if (!trace2_enabled)
762+
if (!trace2_enabled || !value)
763763
return;
764764

765-
redacted = redact_arg(value);
765+
redacted = value ? redact_arg(value): NULL;
766766

767767
for_each_wanted_builtin (j, tgt_j)
768768
if (tgt_j->pfn_param_fl)

trace2/tr2_tgt_event.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,8 @@ static void fn_param_fl(const char *file, int line, const char *param,
491491
event_fmt_prepare(event_name, file, line, NULL, &jw);
492492
jw_object_string(&jw, "scope", scope_name);
493493
jw_object_string(&jw, "param", param);
494-
jw_object_string(&jw, "value", value);
494+
if (value)
495+
jw_object_string(&jw, "value", value);
495496
jw_end(&jw);
496497

497498
tr2_dst_write_line(&tr2dst_event, &jw.json);

trace2/tr2_tgt_normal.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -307,8 +307,9 @@ static void fn_param_fl(const char *file, int line, const char *param,
307307
enum config_scope scope = kvi->scope;
308308
const char *scope_name = config_scope_name(scope);
309309

310-
strbuf_addf(&buf_payload, "def_param scope:%s %s=%s", scope_name, param,
311-
value);
310+
strbuf_addf(&buf_payload, "def_param scope:%s %s", scope_name, param);
311+
if (value)
312+
strbuf_addf(&buf_payload, "=%s", value);
312313
normal_io_write_fl(file, line, &buf_payload);
313314
strbuf_release(&buf_payload);
314315
}

trace2/tr2_tgt_perf.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -446,8 +446,9 @@ static void fn_param_fl(const char *file, int line, const char *param,
446446
struct strbuf scope_payload = STRBUF_INIT;
447447
enum config_scope scope = kvi->scope;
448448
const char *scope_name = config_scope_name(scope);
449-
450-
strbuf_addf(&buf_payload, "%s:%s", param, value);
449+
strbuf_addf(&buf_payload, "%s", param);
450+
if (value)
451+
strbuf_addf(&buf_payload, ":%s", value);
451452
strbuf_addf(&scope_payload, "%s:%s", "scope", scope_name);
452453

453454
perf_io_write_fl(file, line, event_name, NULL, NULL, NULL,

0 commit comments

Comments
 (0)