git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] Segmentation fault on non-commit objects.
@ 2019-10-29  9:27 Davide Berardi
  2019-10-29 13:11 ` Johannes Schindelin
  2019-10-29 14:06 ` Jeff King
  0 siblings, 2 replies; 8+ messages in thread
From: Davide Berardi @ 2019-10-29  9:27 UTC (permalink / raw)
  To: git

Fixed segmentation fault that can be triggered using
$ git clone --branch $object $repository
with object pointing to a non-commit (e.g. a blob).

Signed-off-by: Davide Berardi <berardi.dav@gmail.com>
---
 builtin/clone.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/builtin/clone.c b/builtin/clone.c
index f665b28ccc..6ad2d8fe77 100644
--- a/builtin/clone.c
+++ b/builtin/clone.c
@@ -720,6 +720,9 @@ static void update_head(const struct ref *our, const struct ref *remote,
 	} else if (our) {
 		struct commit *c = lookup_commit_reference(the_repository,
 							   &our->old_oid);
+		/* Check if --branch specifies a non-commit. */
+		if (c == NULL)
+			die(_("unable to update HEAD (cannot find commit)"));
 		/* --branch specifies a non-branch (i.e. tags), detach HEAD */
 		update_ref(msg, "HEAD", &c->object.oid, NULL, REF_NO_DEREF,
 			   UPDATE_REFS_DIE_ON_ERR);
-- 
2.23.0


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

end of thread, other threads:[~2019-11-01  0:29 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-10-29  9:27 [PATCH] Segmentation fault on non-commit objects Davide Berardi
2019-10-29 13:11 ` Johannes Schindelin
2019-11-01  0:26   ` Davide Berardi
2019-10-29 14:06 ` Jeff King
2019-10-30  2:44   ` Junio C Hamano
2019-10-31  5:37     ` Jeff King
2019-10-31 10:43       ` Davide Berardi
2019-11-01  0:29       ` Davide Berardi

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).