{"thread":{"id":"56056","subject":"[PATCH] fetch: Fix segfault on pull --set-upstream outside a branch.","startedAt":"2021-07-06T16:22:49Z","lastAt":"2021-07-06T19:50:26Z","messageCount":5,"participants":["Clemens Fruhwirth","Junio C Hamano","Eric Sunshine"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"429300","messageId":"20210706162238.575988-1-clemens@endorphin.org","threadId":"56056","inReplyTo":null,"subject":"[PATCH] fetch: Fix segfault on pull --set-upstream outside a branch.","fromName":"Clemens Fruhwirth","fromEmail":"clemens@endorphin.org","sentAt":"2021-07-06T16:22:38Z","receivedAt":"2021-07-06T16:22:49Z","isPatch":true,"sender":{"key":"clemens@endorphin.org","avatar":null},"body":"branch_get(\"HEAD\") can return NULL, when we are outside a branch and\nthe user calls pull --set-upstream. Catch this case and warn the user\nto avoid a segfault.\n\nSigned-off-by: Clemens Fruhwirth <clemens@endorphin.org>\n---\n builtin/fetch.c | 4 ++++\n 1 file changed, 4 insertions(+)\n\ndiff --git a/builtin/fetch.c b/builtin/fetch.c\nindex 9191620e50..1097235b90 100644\n--- a/builtin/fetch.c\n+++ b/builtin/fetch.c\n@@ -1602,6 +1602,10 @@ static int do_fetch(struct transport *transport,\n \t\tstruct ref *rm;\n \t\tstruct ref *source_ref = NULL;\n \n+\t\tif (!branch) {\n+\t\t\twarning(_(\"no branch detected to use --set-upstream with.\"));\n+\t\t\tgoto skip;\n+\t\t}\n \t\t/*\n \t\t * We're setting the upstream configuration for the\n \t\t * current branch. The relevant upstream is the\n-- \n2.31.1\n\n"},{"id":"429302","messageId":"xmqq1r8bl40i.fsf@gitster.g","threadId":"56056","inReplyTo":"20210706162238.575988-1-clemens@endorphin.org","subject":"Re: [PATCH] fetch: Fix segfault on pull --set-upstream outside a branch.","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2021-07-06T17:57:01Z","receivedAt":"2021-07-06T17:57:06Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Clemens Fruhwirth <clemens@endorphin.org> writes:\n\n> branch_get(\"HEAD\") can return NULL, when we are outside a branch and\n> the user calls pull --set-upstream. Catch this case and warn the user\n> to avoid a segfault.\n\nNit.  What do you mean by \"outside a branch\"?  If you mean \"when the\nHEAD is detached\", please say so, and use the same terminology in\nyour warning message.\n\nThanks.\n\n>\n> Signed-off-by: Clemens Fruhwirth <clemens@endorphin.org>\n> ---\n>  builtin/fetch.c | 4 ++++\n>  1 file changed, 4 insertions(+)\n>\n> diff --git a/builtin/fetch.c b/builtin/fetch.c\n> index 9191620e50..1097235b90 100644\n> --- a/builtin/fetch.c\n> +++ b/builtin/fetch.c\n> @@ -1602,6 +1602,10 @@ static int do_fetch(struct transport *transport,\n>  \t\tstruct ref *rm;\n>  \t\tstruct ref *source_ref = NULL;\n>  \n> +\t\tif (!branch) {\n> +\t\t\twarning(_(\"no branch detected to use --set-upstream with.\"));\n> +\t\t\tgoto skip;\n> +\t\t}\n>  \t\t/*\n>  \t\t * We're setting the upstream configuration for the\n>  \t\t * current branch. The relevant upstream is the\n"},{"id":"429303","messageId":"CAPig+cTRXTGe-MNTy=2gk1eX8G+0fa303nrLnEtX1uHUC2usmg@mail.gmail.com","threadId":"56056","inReplyTo":"xmqq1r8bl40i.fsf@gitster.g","subject":"Re: [PATCH] fetch: Fix segfault on pull --set-upstream outside a branch.","fromName":"Eric Sunshine","fromEmail":"sunshine@sunshineco.com","sentAt":"2021-07-06T18:03:38Z","receivedAt":"2021-07-06T18:03:51Z","isPatch":true,"sender":{"key":"sunshine@sunshineco.com","avatar":"https://avatars.githubusercontent.com/u/163641?v=4"},"body":"On Tue, Jul 6, 2021 at 1:57 PM Junio C Hamano <gitster@pobox.com> wrote:\n> Clemens Fruhwirth <clemens@endorphin.org> writes:\n>\n> > branch_get(\"HEAD\") can return NULL, when we are outside a branch and\n> > the user calls pull --set-upstream. Catch this case and warn the user\n> > to avoid a segfault.\n>\n> Nit.  What do you mean by \"outside a branch\"?  If you mean \"when the\n> HEAD is detached\", please say so, and use the same terminology in\n> your warning message.\n\nAlso, adding a new test, probably to `t/t5553-set-upstream.sh`, would\nbe welcome. The test can likely be as simple as ensuring that the\ncommand does not crash, and perhaps check that the outcome was as\nexpected.\n"},{"id":"429331","messageId":"xmqqzguzi5q7.fsf@gitster.g","threadId":"56056","inReplyTo":"xmqq1r8bl40i.fsf@gitster.g","subject":"Re: [PATCH] fetch: Fix segfault on pull --set-upstream outside a branch.","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2021-07-06T19:48:16Z","receivedAt":"2021-07-06T19:48:23Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Junio C Hamano <gitster@pobox.com> writes:\n\n> Nit.  What do you mean by \"outside a branch\"?  If you mean \"when the\n> HEAD is detached\", please say so, and use the same terminology in\n> your warning message.\n\nHere is what I queued for today's integration run.  Eric's\nsuggestion to add a simple test is a good idea, too.\n\nThanks.\n\n-- >8 --\nFrom: Clemens Fruhwirth <clemens@endorphin.org>\nDate: Tue, 6 Jul 2021 18:22:38 +0200\nSubject: [PATCH] fetch: fix segfault on pull --set-upstream while on a detached HEAD\n\nbranch_get(\"HEAD\") can return NULL, when HEAD is detached, and cause\nthe code to segfault when the user calls \"pull --set-upstream\".\n\nCatch this case and warn the user to avoid a segfault.\n\nSigned-off-by: Clemens Fruhwirth <clemens@endorphin.org>\nSigned-off-by: Junio C Hamano <gitster@pobox.com>\n---\n builtin/fetch.c | 4 ++++\n 1 file changed, 4 insertions(+)\n\ndiff --git a/builtin/fetch.c b/builtin/fetch.c\nindex dfde96a435..0a11430df4 100644\n--- a/builtin/fetch.c\n+++ b/builtin/fetch.c\n@@ -1602,6 +1602,10 @@ static int do_fetch(struct transport *transport,\n \t\tstruct ref *rm;\n \t\tstruct ref *source_ref = NULL;\n \n+\t\tif (!branch) {\n+\t\t\twarning(_(\"no branch detected to use --set-upstream with.\"));\n+\t\t\tgoto skip;\n+\t\t}\n \t\t/*\n \t\t * We're setting the upstream configuration for the\n \t\t * current branch. The relevant upstream is the\n-- \n2.32.0-288-g654beb0eda\n\n"},{"id":"429332","messageId":"xmqqsg0ri5mq.fsf@gitster.g","threadId":"56056","inReplyTo":"xmqqzguzi5q7.fsf@gitster.g","subject":"Re: [PATCH] fetch: Fix segfault on pull --set-upstream outside a branch.","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2021-07-06T19:50:21Z","receivedAt":"2021-07-06T19:50:26Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Junio C Hamano <gitster@pobox.com> writes:\n\n> Junio C Hamano <gitster@pobox.com> writes:\n>\n>> Nit.  What do you mean by \"outside a branch\"?  If you mean \"when the\n>> HEAD is detached\", please say so, and use the same terminology in\n>> your warning message.\n>\n> Here is what I queued for today's integration run.  Eric's\n> suggestion to add a simple test is a good idea, too.\n\nOops, wrong patch.\n-- >8 --\nFrom: Clemens Fruhwirth <clemens@endorphin.org>\nDate: Tue, 6 Jul 2021 18:22:38 +0200\nSubject: [PATCH] fetch: fix segfault on --set-upstream while on a detached HEAD\n\nbranch_get(\"HEAD\") can return NULL, when HEAD is detached, and cause\nthe code to segfault when the user calls \"git pull --set-upstream\".\n\nCatch this case and warn the user to avoid a segfault.\n\nSigned-off-by: Clemens Fruhwirth <clemens@endorphin.org>\nSigned-off-by: Junio C Hamano <gitster@pobox.com>\n---\n builtin/fetch.c | 4 ++++\n 1 file changed, 4 insertions(+)\n\ndiff --git a/builtin/fetch.c b/builtin/fetch.c\nindex dfde96a435..4efdd28396 100644\n--- a/builtin/fetch.c\n+++ b/builtin/fetch.c\n@@ -1602,6 +1602,10 @@ static int do_fetch(struct transport *transport,\n \t\tstruct ref *rm;\n \t\tstruct ref *source_ref = NULL;\n \n+\t\tif (!branch) {\n+\t\t\twarning(_(\"not on a branch to use --set-upstream with\"));\n+\t\t\tgoto skip;\n+\t\t}\n \t\t/*\n \t\t * We're setting the upstream configuration for the\n \t\t * current branch. The relevant upstream is the\n-- \n2.32.0-288-g654beb0eda\n\n"}]}