git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 1/5] t7060: add test for status --branch on a detached HEAD

From
René Scharfe <l.s.r@web.de>
Date
Oct 31, 2015, 17:35 UTC
Message-ID
<5634FBE4.9030406@web.de>
In-Reply-To
<5634FB59.1000506@web.de>

This test fails when run under Valgrind because branch_get() gets passed a bogus branch name pointer:

==62831== Invalid read of size 1 ==62831== at 0x4F76AE: branch_get (remote.c:1650) ==62831== by 0x53499E: wt_shortstatus_print_tracking (wt-status.c:1654) ==62831== by 0x53499E: wt_shortstatus_print (wt-status.c:1706) ==62831== by 0x428D29: cmd_status (commit.c:1384) ==62831== by 0x405D6D: run_builtin (git.c:350) ==62831== by 0x405D6D: handle_builtin (git.c:536) ==62831== by 0x404F10: run_argv (git.c:582) ==62831== by 0x404F10: main (git.c:690) ==62831== Address 0x5e89b0b is 6 bytes after a block of size 5 alloc'd ==62831== at 0x4C28C4F: malloc (vg_replace_malloc.c:299) ==62831== by 0x59579E9: strdup (strdup.c:42) ==62831== by 0x52E108: xstrdup (wrapper.c:43) ==62831== by 0x5322A6: wt_status_prepare (wt-status.c:130) ==62831== by 0x4276E0: status_init_config (commit.c:184) ==62831== by 0x428BB8: cmd_status (commit.c:1350) ==62831== by 0x405D6D: run_builtin (git.c:350) ==62831== by 0x405D6D: handle_builtin (git.c:536) ==62831== by 0x404F10: run_argv (git.c:582) ==62831== by 0x404F10: main (git.c:690)

Signed-off-by: Rene Scharfe <l.s.r@web.de>
---
 t/t7060-wtstatus.sh | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
diff --git a/t/t7060-wtstatus.sh b/t/t7060-wtstatus.sh
index 32d8176..e6af772 100755
--- a/t/t7060-wtstatus.sh
+++ b/t/t7060-wtstatus.sh
@@ -213,5 +213,19 @@ EOF
 	git checkout master
 '
 
+test_expect_failure 'status --branch with detached HEAD' '
+	git reset --hard &&
+	git checkout master^0 &&
+	git status --branch --porcelain >actual &&
+	cat >expected <<-EOF &&
+	## HEAD (no branch)
+	?? .gitconfig
+	?? actual
+	?? expect
+	?? expected
+	?? mdconflict/
+	EOF
+	test_i18ncmp expected actual
+'
 
 test_done
-- 
2.6.2
Previous: René ScharfeNext: René Scharfe
Message 2 of 10 in “wt-status: fix an invalid memory read, clean up”
  1. 0/5 wt-status: fix an invalid memory read, clean upRené Scharfe, Oct 31, 2015
  2. 1/5 t7060: add test for status --branch on a detached HEADRené Scharfe, Oct 31, 2015
  3. 2/5 wt-status: exit early using goto in wt_shortstatus_print_tracking()René Scharfe, Oct 31, 2015
  4. 3/5 wt-status: avoid building bogus branch name with detached HEADRené Scharfe, Oct 31, 2015
  5. Junio C HamanoNov 1, 2015
  6. René ScharfeNov 1, 2015
  7. 4/5 wt-status: don't skip a magical number of characters blindlyRené Scharfe, Oct 31, 2015
  8. Junio C HamanoNov 1, 2015
  9. Junio C HamanoNov 1, 2015
  10. 5/5 wt-status: use skip_prefix() to get rid of magic string length constantsRené Scharfe, Oct 31, 2015

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.