]> git.ipfire.org Git - thirdparty/git.git/commitdiff
trace2: prevent segfault on config collection with valueless true
authorAdam Murray <ad@canva.com>
Fri, 10 Jan 2025 07:28:20 +0000 (07:28 +0000)
committerJunio C Hamano <gitster@pobox.com>
Thu, 23 Jan 2025 18:01:56 +0000 (10:01 -0800)
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>
t/t0210-trace2-normal.sh
trace2.c
trace2/tr2_tgt_event.c
trace2/tr2_tgt_normal.c
trace2/tr2_tgt_perf.c

index c312657a12cd34334ce58361c7f0a73f384daff6..07b66089513ad58d17da5697705147029c68a7fa 100755 (executable)
@@ -244,6 +244,15 @@ test_expect_success 'bug messages followed by BUG() are written to trace2' '
        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
 
 # Now test without environment variables and get all Trace2 settings
index f894532d05331c48607fc3434b8d31937f951a4b..e67edf4b1b6db0bbc7353b73d63476e79bd1bb63 100644 (file)
--- a/trace2.c
+++ b/trace2.c
@@ -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)
index 59910a1a4f7c0f280fb6839873429d9cc877d3cf..4bf59ebbe04e97b510ac8083303ac65bf595af0f 100644 (file)
@@ -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);
index baef48aa6989cede1d8bf62837388ab3379e9604..924736ab36093bb27f9e5f9fbf2a5cc0ff6183b4 100644 (file)
@@ -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);
 }
index a6f9a8a193e058fc164a8e9bd8dc823b7a317a85..19ae7433ef8d8c85e8ca2f7dd7c284749c761981 100644 (file)
@@ -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_addstr(&buf_payload, 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,