Thread (1 message) 1 message, 1 author, 2021-07-06

Re: [PATCH] fetch: Fix segfault on pull --set-upstream outside a branch.

From: Junio C Hamano <hidden>
Date: 2021-07-06 19:50:26
Subsystem: the rest · Maintainer: Linus Torvalds

Possibly related (same subject, not in this thread)

Junio C Hamano [off-list ref] writes:
Junio C Hamano [off-list ref] writes:
quoted
Nit.  What do you mean by "outside a branch"?  If you mean "when the
HEAD is detached", please say so, and use the same terminology in
your warning message.
Here is what I queued for today's integration run.  Eric's
suggestion to add a simple test is a good idea, too.
Oops, wrong patch.
-- >8 --
From: Clemens Fruhwirth <redacted>
Date: Tue, 6 Jul 2021 18:22:38 +0200
Subject: [PATCH] fetch: fix segfault on --set-upstream while on a detached HEAD

branch_get("HEAD") can return NULL, when HEAD is detached, and cause
the code to segfault when the user calls "git pull --set-upstream".

Catch this case and warn the user to avoid a segfault.

Signed-off-by: Clemens Fruhwirth <redacted>
Signed-off-by: Junio C Hamano <redacted>
---
 builtin/fetch.c | 4 ++++
 1 file changed, 4 insertions(+)
diff --git a/builtin/fetch.c b/builtin/fetch.c
index dfde96a435..4efdd28396 100644
--- a/builtin/fetch.c
+++ b/builtin/fetch.c
@@ -1602,6 +1602,10 @@ static int do_fetch(struct transport *transport,
 		struct ref *rm;
 		struct ref *source_ref = NULL;
 
+		if (!branch) {
+			warning(_("not on a branch to use --set-upstream with"));
+			goto skip;
+		}
 		/*
 		 * We're setting the upstream configuration for the
 		 * current branch. The relevant upstream is the
-- 
2.32.0-288-g654beb0eda
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help