mirror of
https://github.com/git-for-windows/git.git
synced 2025-12-12 04:41:35 -06:00
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>
This commit is contained in:
parent
5c21db3a0d
commit
2fd367cf63
@ -244,6 +244,15 @@ test_expect_success 'bug messages followed by BUG() are written to trace2' '
|
|||||||
test_cmp expect actual
|
test_cmp expect actual
|
||||||
'
|
'
|
||||||
|
|
||||||
|
test_expect_success 'a valueless true configuration variable is handled' '
|
||||||
|
test_when_finished "rm -f trace2.normal actual expect" &&
|
||||||
|
echo >expect &&
|
||||||
|
GIT_TRACE2="$(pwd)/trace2.normal" \
|
||||||
|
GIT_TRACE2_CONFIG_PARAMS=foo.true \
|
||||||
|
git -c foo.true config foo.true >actual &&
|
||||||
|
test_cmp expect actual
|
||||||
|
'
|
||||||
|
|
||||||
sane_unset GIT_TRACE2_BRIEF
|
sane_unset GIT_TRACE2_BRIEF
|
||||||
|
|
||||||
# Now test without environment variables and get all Trace2 settings
|
# Now test without environment variables and get all Trace2 settings
|
||||||
|
|||||||
2
trace2.c
2
trace2.c
@ -762,7 +762,7 @@ void trace2_def_param_fl(const char *file, int line, const char *param,
|
|||||||
if (!trace2_enabled)
|
if (!trace2_enabled)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
redacted = redact_arg(value);
|
redacted = value ? redact_arg(value) : NULL;
|
||||||
|
|
||||||
for_each_wanted_builtin (j, tgt_j)
|
for_each_wanted_builtin (j, tgt_j)
|
||||||
if (tgt_j->pfn_param_fl)
|
if (tgt_j->pfn_param_fl)
|
||||||
|
|||||||
@ -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);
|
event_fmt_prepare(event_name, file, line, NULL, &jw);
|
||||||
jw_object_string(&jw, "scope", scope_name);
|
jw_object_string(&jw, "scope", scope_name);
|
||||||
jw_object_string(&jw, "param", param);
|
jw_object_string(&jw, "param", param);
|
||||||
jw_object_string(&jw, "value", value);
|
if (value)
|
||||||
|
jw_object_string(&jw, "value", value);
|
||||||
jw_end(&jw);
|
jw_end(&jw);
|
||||||
|
|
||||||
tr2_dst_write_line(&tr2dst_event, &jw.json);
|
tr2_dst_write_line(&tr2dst_event, &jw.json);
|
||||||
|
|||||||
@ -307,8 +307,9 @@ static void fn_param_fl(const char *file, int line, const char *param,
|
|||||||
enum config_scope scope = kvi->scope;
|
enum config_scope scope = kvi->scope;
|
||||||
const char *scope_name = config_scope_name(scope);
|
const char *scope_name = config_scope_name(scope);
|
||||||
|
|
||||||
strbuf_addf(&buf_payload, "def_param scope:%s %s=%s", scope_name, param,
|
strbuf_addf(&buf_payload, "def_param scope:%s %s", scope_name, param);
|
||||||
value);
|
if (value)
|
||||||
|
strbuf_addf(&buf_payload, "=%s", value);
|
||||||
normal_io_write_fl(file, line, &buf_payload);
|
normal_io_write_fl(file, line, &buf_payload);
|
||||||
strbuf_release(&buf_payload);
|
strbuf_release(&buf_payload);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -446,8 +446,9 @@ static void fn_param_fl(const char *file, int line, const char *param,
|
|||||||
struct strbuf scope_payload = STRBUF_INIT;
|
struct strbuf scope_payload = STRBUF_INIT;
|
||||||
enum config_scope scope = kvi->scope;
|
enum config_scope scope = kvi->scope;
|
||||||
const char *scope_name = config_scope_name(scope);
|
const char *scope_name = config_scope_name(scope);
|
||||||
|
strbuf_addstr(&buf_payload, param);
|
||||||
strbuf_addf(&buf_payload, "%s:%s", param, value);
|
if (value)
|
||||||
|
strbuf_addf(&buf_payload, ":%s", value);
|
||||||
strbuf_addf(&scope_payload, "%s:%s", "scope", scope_name);
|
strbuf_addf(&scope_payload, "%s:%s", "scope", scope_name);
|
||||||
|
|
||||||
perf_io_write_fl(file, line, event_name, NULL, NULL, NULL,
|
perf_io_write_fl(file, line, event_name, NULL, NULL, NULL,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user