git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] http-push: refactor request url creation

From
Junio C Hamano <gitster@pobox.com>
Date
Jan 25, 2009, 20:35 UTC
Message-ID
<7vpribdszr.fsf@gitster.siamese.dyndns.org>
In-Reply-To
<be6fef0d0901242208p635264e5jc1f95d784cd51450@mail.gmail.com>
Ray Chuan <rctay89@gmail.com> writes:
Show 9 quoted lines
> Currently, functions that deal with objects on the remote repository
> have to allocate and do strcpys to generate the URL.
>
> This patch saves them this trouble, by providing a function that
> returns a URL: either the object's 2-digit hex directory (eg.
> /objects/a1/) or the complete object location (eg. /objects/a1/b2).
>
> Acked-by: Johannes Schindelin <johannes.schindelin@gmx.de>
> Signed-off-by: Tay Ray Chuan <rctay89@gmail.com>

If you wrote it, and then Johannes vetted it, then these two should be in the opposite order.

> +static char *get_remote_object_url(const char *url, const char *hex,
> int only_two_digit_prefix) {
Linewrapped.
> +	struct strbuf buf = STRBUF_INIT;
> +
> +	strbuf_addf(&buf, "%sobjects/%.*s/", url, 2, hex);
> +	if(!only_two_digit_prefix)
"if (..."
Show 12 quoted lines
> @@ -304,17 +312,7 @@ static void start_fetch_loose(struct
> transfer_request *request)
>
>  	git_SHA1_Init(&request->c);
>
> -	url = xmalloc(strlen(remote->url) + 50);
> ...
> -	strcpy(request->url, url);
> +	request->url = get_remote_object_url(remote->url, hex, 0);
> ...
> -	curl_easy_setopt(slot->curl, CURLOPT_URL, url);
> +	curl_easy_setopt(slot->curl, CURLOPT_URL, request->url);

The original code gave a separate "url" to setop() but this gives the same string. Does curl_easy_setop() copies the given string away? IOW is this change safe?

Show 9 quoted lines
> @@ -550,21 +540,11 @@ static void start_put(struct transfer_request *request)
>
>  	request->buffer.buf.len = stream.total_out;
>
> -	request->url = xmalloc(strlen(remote->url) +
> ...
> -	strcpy(posn, request->lock->token);
> +	strbuf_addf(&url_buf, "Destination: %s",
> get_remote_object_url(remote->url, hex, 0));
Linewrapped.
The return value from get_remote_object_url() leaks here.
> +	request->dest = strbuf_detach(&url_buf, NULL);
> +
> +	strbuf_addf(&url_buf, "%s_%s", get_remote_object_url(remote->url,
> hex, 0), request->lock->token);
The return value from get_remote_object_url() leaks here, too.
Previous: Ray ChuanNext: Ray Chuan
Message 2 of 6 in “http-push: refactor request url creation”
  1. http-push: refactor request url creationRay Chuan, Jan 25, 2009
  2. Junio C HamanoJan 25, 2009
  3. Ray ChuanJan 26, 2009
  4. Daniel StenbergJan 26, 2009
  5. Johannes SchindelinJan 26, 2009
  6. Junio C HamanoJan 27, 2009

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.