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

Re: [PATCH 3/3] Rename resolve_ref() to resolve_ref_unsafe()

From
Jonathan Nieder <jrnieder@gmail.com>
Date
Dec 10, 2011, 20:55 UTC
Message-ID
<20111210205519.GA24817@elie.hsd1.il.comcast.net>
In-Reply-To
<1323521631-24320-3-git-send-email-pclouds@gmail.com>
Nguyễn Thái Ngọc Duy wrote:
> resolve_ref() may return a pointer to a shared buffer and can be
> overwritten by the next resolve_ref() calls. Callers need to
> pay attention, not to keep the pointer when the next call happens.
[...]
Show 8 quoted lines
> --- a/branch.c
> +++ b/branch.c
> @@ -182,7 +182,7 @@ int validate_new_branchname(const char *name, struct strbuf *ref,
>  		const char *head;
>  		unsigned char sha1[20];
>  
> -		head = resolve_ref("HEAD", sha1, 0, NULL);
> +		head = resolve_ref_unsafe("HEAD", sha1, 0, NULL);

I wonder if it would make sense to have a separate function that maintains a shared buffer describing what HEAD resolves to, lazily loaded. Would invalidating the cache when appropriate be too fussy and subtle?

[...]
Show 7 quoted lines
> +++ b/transport.c
> @@ -163,7 +163,7 @@ static void set_upstreams(struct transport *transport, struct ref *refs,
>  		/* Follow symbolic refs (mainly for HEAD). */
>  		localname = ref->peer_ref->name;
>  		remotename = ref->name;
> -		tmp = resolve_ref(localname, sha, 1, &flag);
> +		tmp = resolve_ref_unsafe(localname, sha, 1, &flag);

Anyway, this patch looks sane. The reminder seems useful and doesn't feel over-the-top.

Previous: Nguyễn Thái Ngọc DuyNext: Nguyen Thai Ngoc Duy
Message 6 of 10 in “Convert resolve_ref+xstrdup to new resolve_refdup function”
  1. 1/3 Convert resolve_ref+xstrdup to new resolve_refdup functionNguyễn Thái Ngọc Duy, Dec 10, 2011
  2. 2/3 Guard memory overwriting in resolve_ref's static bufferNguyễn Thái Ngọc Duy, Dec 10, 2011
  3. Jonathan NiederDec 10, 2011
  4. Nguyen Thai Ngoc DuyDec 11, 2011
  5. 3/3 Rename resolve_ref() to resolve_ref_unsafe()Nguyễn Thái Ngọc Duy, Dec 10, 2011
  6. Jonathan NiederDec 10, 2011
  7. Nguyen Thai Ngoc DuyDec 11, 2011
  8. Jonathan NiederDec 10, 2011
  9. Nguyen Thai Ngoc DuyDec 10, 2011
  10. Junio C HamanoDec 12, 2011

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.