Git fork

trace2: prevent segfault on config collection with valueless true

When TRACE2 analytics is enabled, a configuration variable set to
"valueless true" 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

Add checks to prevent the segfault and instead show that the
variable without value.

Signed-off-by: Adam Murray <ad@canva.com>
Acked-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

authored by

Adam Murray and committed by
Junio C Hamano
2fd367cf 5c21db3a

+18 -6
+9
t/t0210-trace2-normal.sh
··· 244 test_cmp expect actual 245 ' 246 247 sane_unset GIT_TRACE2_BRIEF 248 249 # Now test without environment variables and get all Trace2 settings
··· 244 test_cmp expect actual 245 ' 246 247 + test_expect_success 'a valueless true configuration variable is handled' ' 248 + test_when_finished "rm -f trace2.normal actual expect" && 249 + echo >expect && 250 + GIT_TRACE2="$(pwd)/trace2.normal" \ 251 + GIT_TRACE2_CONFIG_PARAMS=foo.true \ 252 + git -c foo.true config foo.true >actual && 253 + test_cmp expect actual 254 + ' 255 + 256 sane_unset GIT_TRACE2_BRIEF 257 258 # Now test without environment variables and get all Trace2 settings
+1 -1
trace2.c
··· 762 if (!trace2_enabled) 763 return; 764 765 - redacted = redact_arg(value); 766 767 for_each_wanted_builtin (j, tgt_j) 768 if (tgt_j->pfn_param_fl)
··· 762 if (!trace2_enabled) 763 return; 764 765 + redacted = value ? redact_arg(value) : NULL; 766 767 for_each_wanted_builtin (j, tgt_j) 768 if (tgt_j->pfn_param_fl)
+2 -1
trace2/tr2_tgt_event.c
··· 491 event_fmt_prepare(event_name, file, line, NULL, &jw); 492 jw_object_string(&jw, "scope", scope_name); 493 jw_object_string(&jw, "param", param); 494 - jw_object_string(&jw, "value", value); 495 jw_end(&jw); 496 497 tr2_dst_write_line(&tr2dst_event, &jw.json);
··· 491 event_fmt_prepare(event_name, file, line, NULL, &jw); 492 jw_object_string(&jw, "scope", scope_name); 493 jw_object_string(&jw, "param", param); 494 + if (value) 495 + jw_object_string(&jw, "value", value); 496 jw_end(&jw); 497 498 tr2_dst_write_line(&tr2dst_event, &jw.json);
+3 -2
trace2/tr2_tgt_normal.c
··· 307 enum config_scope scope = kvi->scope; 308 const char *scope_name = config_scope_name(scope); 309 310 - strbuf_addf(&buf_payload, "def_param scope:%s %s=%s", scope_name, param, 311 - value); 312 normal_io_write_fl(file, line, &buf_payload); 313 strbuf_release(&buf_payload); 314 }
··· 307 enum config_scope scope = kvi->scope; 308 const char *scope_name = config_scope_name(scope); 309 310 + strbuf_addf(&buf_payload, "def_param scope:%s %s", scope_name, param); 311 + if (value) 312 + strbuf_addf(&buf_payload, "=%s", value); 313 normal_io_write_fl(file, line, &buf_payload); 314 strbuf_release(&buf_payload); 315 }
+3 -2
trace2/tr2_tgt_perf.c
··· 446 struct strbuf scope_payload = STRBUF_INIT; 447 enum config_scope scope = kvi->scope; 448 const char *scope_name = config_scope_name(scope); 449 - 450 - strbuf_addf(&buf_payload, "%s:%s", param, value); 451 strbuf_addf(&scope_payload, "%s:%s", "scope", scope_name); 452 453 perf_io_write_fl(file, line, event_name, NULL, NULL, NULL,
··· 446 struct strbuf scope_payload = STRBUF_INIT; 447 enum config_scope scope = kvi->scope; 448 const char *scope_name = config_scope_name(scope); 449 + strbuf_addstr(&buf_payload, param); 450 + if (value) 451 + strbuf_addf(&buf_payload, ":%s", value); 452 strbuf_addf(&scope_payload, "%s:%s", "scope", scope_name); 453 454 perf_io_write_fl(file, line, event_name, NULL, NULL, NULL,