[PATCH] BUG: git push on an empty clone segfaults.

Subsystems: the rest

DORMANTno replies

3 messages, 3 authors, 2016-06-15 · open the first message on its own page

[PATCH] BUG: git push on an empty clone segfaults.

From: Matthieu Moy <hidden>
Date: 2016-06-15 22:46:37

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.

Signed-off-by: Matthieu Moy <redacted>
---
 t/t5701-clone-local.sh |   10 ++++++++++
 1 files changed, 10 insertions(+), 0 deletions(-)
diff --git a/t/t5701-clone-local.sh b/t/t5701-clone-local.sh
index 3559d17..7c6ef4c 100755
--- a/t/t5701-clone-local.sh
+++ b/t/t5701-clone-local.sh
@@ -132,4 +132,14 @@ test_expect_success 'clone empty repository' '
 	 test $actual = $expected)
 '
 
+test_expect_failure 'clone empty repository, and then push should not segfault.' '
+	cd "$D" &&
+	rm -fr empty/ empty-clone/ &&
+	mkdir empty &&
+	(cd empty && git init) &&
+	git clone empty empty-clone &&
+	cd empty-clone &&
+	test_must_fail git push
+'
+
 test_done
-- 
1.6.2.2.449.g92961.dirty

[PATCH] Fix uninitialized memory in get_local_heads()

From: Johannes Schindelin <hidden>
Date: 2016-06-15 22:46:37

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

	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

Re: [PATCH] Fix uninitialized memory in get_local_heads()

From: Jay Soffian <hidden>
Date: 2016-06-15 22:46:37

On Mon, Apr 20, 2009 at 6:20 AM, Johannes Schindelin
[off-list ref] wrote:
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 <redacted>
Doh. Thank you for the fix.

j.
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help