Re: [PATCH v3] remote-curl: send Accept-Language header to server
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Jun 13, 2022, 21:32 UTC
- Message-ID
- <xmqq1qvs5jx4.fsf@gitster.g>
- In-Reply-To
- <pull.1251.v3.git.1655054421697.gitgitgadget@gmail.com>
"Li Linchao via GitGitGadget" <gitgitgadget@gmail.com> writes:
Show 43 quoted lines
> @@ -932,6 +933,10 @@ static int post_rpc(struct rpc_state *rpc, int stateless_connect, int flush_rece
> headers = curl_slist_append(headers, needs_100_continue ?
> "Expect: 100-continue" : "Expect:");
>
> + /* Add Accept-Language header */
> + if (rpc->hdr_accept_language)
> + headers = curl_slist_append(headers, rpc->hdr_accept_language);
> +
> /* Add the extra Git-Protocol header */
> if (rpc->protocol_header)
> headers = curl_slist_append(headers, rpc->protocol_header);
> @@ -1080,6 +1085,8 @@ static int rpc_service(struct rpc_state *rpc, struct discovery *heads,
> strbuf_addf(&buf, "%s%s", url.buf, svc);
> rpc->service_url = strbuf_detach(&buf, NULL);
>
> + rpc->hdr_accept_language = xstrdup_or_null(http_get_accept_language_header());
> +
> strbuf_addf(&buf, "Content-Type: application/x-%s-request", svc);
> rpc->hdr_content_type = strbuf_detach(&buf, NULL);
>
> @@ -1118,6 +1125,7 @@ static int rpc_service(struct rpc_state *rpc, struct discovery *heads,
> free(rpc->service_url);
> free(rpc->hdr_content_type);
> free(rpc->hdr_accept);
> + free(rpc->hdr_accept_language);
> free(rpc->protocol_header);
> free(rpc->buf);
> strbuf_release(&buf);
> @@ -1400,6 +1408,7 @@ static int stateless_connect(const char *service_name)
> struct discovery *discover;
> struct rpc_state rpc;
> struct strbuf buf = STRBUF_INIT;
> + const char *accept_language;
>
> /*
> * Run the info/refs request and see if the server supports protocol
> @@ -1418,6 +1427,9 @@ static int stateless_connect(const char *service_name)
> printf("\n");
> fflush(stdout);
> }
> + accept_language = http_get_accept_language_header();
> + if (accept_language)
> + rpc.hdr_accept_language = xstrfmt("%s", accept_language);Isn't rpc.hdr_accept_language left uninitialized garbage if accept_language is NULL? It is the same bug I pointed out earlier, whose fix may have to be different.
Has this been tested? I got immediate segfault with this patch in 'seen'.