Skip to content

Commit 2253303

Browse files
committed
trace2: prevent segfault on config collection where no value specified
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 a null check to prevent the segfault and instead return the "empty config value" error.
1 parent 8f8d6ee commit 2253303

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -759,7 +759,7 @@ 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

765765
redacted = redact_arg(value);

0 commit comments

Comments
 (0)