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:
Adam Murray
2025-01-10 07:28:20 +00:00
committed by Junio C Hamano
parent 5c21db3a0d
commit 2fd367cf63
5 changed files with 18 additions and 6 deletions

View File

@@ -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