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

Re: [PATCH 4/4] bundle: keep around names passed to add_pending_object()

From
Junio C Hamano <gitster@pobox.com>
Date
Mar 1, 2012, 22:05 UTC
Message-ID
<7vehtckmee.fsf@alter.siamese.dyndns.org>
In-Reply-To
<6fba13f255f76481dc9098b5e8fbb33bd10735cb.1330637923.git.trast@student.ethz.ch>
Thomas Rast <trast@student.ethz.ch> writes:
Show 8 quoted lines
> The 'name' field passed to add_pending_object() is used to later
> deduplicate in object_array_remove_duplicates().
>
> git-bundle had a bug in this area since 18449ab (git-bundle: avoid
> packing objects which are in the prerequisites, 2007-03-08): it passed
> the name of each boundary object in a static buffer.  In other words,
> all that object_array_remove_duplicates() saw was the name of the
> *last* added boundary object.
Ouch.
Show 10 quoted lines
> diff --git a/bundle.c b/bundle.c
> index 7a760db..d9cfd90 100644
> --- a/bundle.c
> +++ b/bundle.c
> @@ -273,7 +273,7 @@ int create_bundle(struct bundle_header *header, const char *path,
>  			if (!get_sha1_hex(buf.buf + 1, sha1)) {
>  				struct object *object = parse_object(sha1);
>  				object->flags |= UNINTERESTING;
> -				add_pending_object(&revs, object, buf.buf);
> +				add_pending_object(&revs, object, xstrdup(buf.buf));

We'll release &buf after the loop but the elements in the pending object array will keep their own copies, so now we would be safe.

Thanks for fixing this.
Previous: Thomas RastNext: Thomas Rast
Message 10 of 11 in “Another bundle fix: reading freed memory”
  1. 0/4 Another bundle fix: reading freed memoryThomas Rast, Mar 1, 2012
  2. 1/4 t5510: refactor bundle->pack conversionThomas Rast, Mar 1, 2012
  3. 2/4 t5510: fix indent with spacesThomas Rast, Mar 1, 2012
  4. 3/4 t5510: ensure we stay in the toplevel test dirThomas Rast, Mar 1, 2012
  5. Junio C HamanoMar 1, 2012
  6. Thomas RastMar 1, 2012
  7. Junio C HamanoMar 1, 2012
  8. Junio C HamanoMar 1, 2012
  9. 4/4 bundle: keep around names passed to add_pending_object()Thomas Rast, Mar 1, 2012
  10. Junio C HamanoMar 1, 2012
  11. Thomas RastMar 1, 2012

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.