git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] trace2: prevent segfault on config collection where no value specified
@ 2024-11-07  0:04 Adam Murray via GitGitGadget
  2024-11-07  2:01 ` Jeff King
  2025-01-10  7:28 ` [PATCH v2] " Adam Murray via GitGitGadget
  0 siblings, 2 replies; 11+ messages in thread
From: Adam Murray via GitGitGadget @ 2024-11-07  0:04 UTC (permalink / raw)
  To: git; +Cc: Adam Murray, Adam Murray

From: Adam Murray <ad@canva.com>

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.

Signed-off-by: Adam Murray <ad@canva.com>
---
    trace2: prevent segfault on config collection where no value specified

Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-1814%2Fad-murray%2Ffix-trace2-segfault-v1
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-1814/ad-murray/fix-trace2-segfault-v1
Pull-Request: https://github.com/gitgitgadget/git/pull/1814

 t/t0210-trace2-normal.sh | 8 ++++++++
 trace2.c                 | 2 +-
 2 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/t/t0210-trace2-normal.sh b/t/t0210-trace2-normal.sh
index b9adc94aab4..4047ab562a4 100755
--- a/t/t0210-trace2-normal.sh
+++ b/t/t0210-trace2-normal.sh
@@ -244,6 +244,14 @@ test_expect_success 'bug messages followed by BUG() are written to trace2' '
 	test_cmp expect actual
 '
 
+test_expect_success 'empty configuration values are handled' '
+  test_when_finished "rm trace2.normal actual expect" &&
+  echo >expect &&
+  GIT_TRACE2="$(pwd)/trace2.normal"  GIT_TRACE2_CONFIG_PARAMS=foo.empty \
+	  git -c foo.empty config foo.empty >actual &&
+	test_cmp expect actual
+'
+
 sane_unset GIT_TRACE2_BRIEF
 
 # Now test without environment variables and get all Trace2 settings
diff --git a/trace2.c b/trace2.c
index f894532d053..5df43478b8f 100644
--- a/trace2.c
+++ b/trace2.c
@@ -759,7 +759,7 @@ void trace2_def_param_fl(const char *file, int line, const char *param,
 	int j;
 	const char *redacted;
 
-	if (!trace2_enabled)
+	if (!trace2_enabled || !value)
 		return;
 
 	redacted = redact_arg(value);

base-commit: 8f8d6eee531b3fa1a8ef14f169b0cb5035f7a772
-- 
gitgitgadget

^ permalink raw reply related	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2025-01-23 21:15 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-11-07  0:04 [PATCH] trace2: prevent segfault on config collection where no value specified Adam Murray via GitGitGadget
2024-11-07  2:01 ` Jeff King
2024-11-07  3:02   ` Junio C Hamano
2025-01-10  7:28 ` [PATCH v2] " Adam Murray via GitGitGadget
2025-01-10 17:10   ` Junio C Hamano
2025-01-22 10:11   ` Johannes Schindelin
2025-01-22 18:12     ` Junio C Hamano
2025-01-22 18:18       ` Junio C Hamano
2025-01-23 17:01         ` D. Ben Knoble
2025-01-23 18:02           ` Junio C Hamano
2025-01-23 21:15             ` D. Ben Knoble

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).