Skip to content

Commit

Permalink
receive-pack: fix "borrowing from alternate object store" implementation
Browse files Browse the repository at this point in the history
In the alternate_object_database structure, ent->base[] is a buffer the
users can use to form pathnames to loose objects, and ent->name is a
pointer into that buffer (it points at one beyond ".git/objects/").  If
you get a call to add_refs_from_alternate() after somebody used the entry
(has_loose_object() has been called, for example), *ent->name would not be
NUL, and ent->base[] won't be the path to the object store.

This caller is expecting to read the path to the object store in ent->base[];
it needs to NUL terminate the buffer if it wants to.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Junio C Hamano committed Oct 26, 2008
1 parent 53ffb87 commit b849253
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions builtin-receive-pack.c
Original file line number Diff line number Diff line change
Expand Up @@ -466,12 +466,17 @@ static int delete_only(struct command *cmd)

static int add_refs_from_alternate(struct alternate_object_database *e, void *unused)
{
char *other = xstrdup(make_absolute_path(e->base));
size_t len = strlen(other);
char *other;
size_t len;
struct remote *remote;
struct transport *transport;
const struct ref *extra;

e->name[-1] = '\0';
other = xstrdup(make_absolute_path(e->base));
e->name[-1] = '/';
len = strlen(other);

while (other[len-1] == '/')
other[--len] = '\0';
if (len < 8 || memcmp(other + len - 8, "/objects", 8))
Expand Down

0 comments on commit b849253

Please sign in to comment.