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

[PATCH] Fix uninitialized memory in get_local_heads()

From
Johannes Schindelin <johannes.schindelin@gmx.de>
Date
Apr 20, 2009, 10:20 UTC
Message-ID
<alpine.DEB.1.00.0904201219240.6955@intel-tinevez-2-302>
In-Reply-To
<1240220930-24679-1-git-send-email-Matthieu.Moy@imag.fr>

In 454e202(move duplicated get_local_heads() to remote.c), a static local variable was moved into a function, but not initialized.

This resulted in a crash when trying to push from an empty repository.
Noticed by Matthieu Moy.
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
---
	On Mon, 20 Apr 2009, Matthieu Moy wrote:
	> Ideally, "git push" from an empty repository to another empty 
	> one should be a no-op, or perhaps should error out cleanly.
	> Currently, it just segfaults.
	Good catch.  This patch goes on top of yours.
	/me is running valgrind now.
 remote.c               |    2 +-
 t/t5701-clone-local.sh |    2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/remote.c b/remote.c
index a06761a..e4c89b8 100644
--- a/remote.c
+++ b/remote.c
@@ -1504,7 +1504,7 @@ static int one_local_ref(const char *refname, const unsigned char *sha1, int fla
 
 struct ref *get_local_heads(void)
 {
-	struct ref *local_refs, **local_tail = &local_refs;
+	struct ref *local_refs = NULL, **local_tail = &local_refs;
 	for_each_ref(one_local_ref, &local_tail);
 	return local_refs;
 }
diff --git a/t/t5701-clone-local.sh b/t/t5701-clone-local.sh
index 7c6ef4c..f26b511 100755
--- a/t/t5701-clone-local.sh
+++ b/t/t5701-clone-local.sh
@@ -132,7 +132,7 @@ test_expect_success 'clone empty repository' '
 	 test $actual = $expected)
 '
 
-test_expect_failure 'clone empty repository, and then push should not segfault.' '
+test_expect_success 'clone empty repository, and then push should not segfault.' '
 	cd "$D" &&
 	rm -fr empty/ empty-clone/ &&
 	mkdir empty &&
-- 
1.6.2.1.493.g67cf3
Previous: Matthieu MoyNext: Jay Soffian
Message 2 of 11 in “BUG: git push on an empty clone segfaults.”
  1. BUG: git push on an empty clone segfaults.Matthieu Moy, Apr 20, 2009
  2. Fix uninitialized memory in get_local_heads()Johannes Schindelin, Apr 20, 2009
  3. Jay SoffianApr 20, 2009
  4. Junio C HamanoApr 20, 2009
  5. Johannes SchindelinApr 20, 2009
  6. Junio C HamanoApr 20, 2009
  7. Petr BaudisApr 20, 2009
  8. Johannes SchindelinApr 20, 2009
  9. Petr BaudisApr 20, 2009
  10. Matthieu MoyApr 20, 2009
  11. clone: add test for push on an empty clone.Matthieu Moy, Apr 20, 2009

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.