Skip to content

Commit b849253

Browse files
committed
receive-pack: fix "borrowing from alternate object store" implementation
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>
1 parent 53ffb87 commit b849253

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

builtin-receive-pack.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -466,12 +466,17 @@ static int delete_only(struct command *cmd)
466466

467467
static int add_refs_from_alternate(struct alternate_object_database *e, void *unused)
468468
{
469-
char *other = xstrdup(make_absolute_path(e->base));
470-
size_t len = strlen(other);
469+
char *other;
470+
size_t len;
471471
struct remote *remote;
472472
struct transport *transport;
473473
const struct ref *extra;
474474

475+
e->name[-1] = '\0';
476+
other = xstrdup(make_absolute_path(e->base));
477+
e->name[-1] = '/';
478+
len = strlen(other);
479+
475480
while (other[len-1] == '/')
476481
other[--len] = '\0';
477482
if (len < 8 || memcmp(other + len - 8, "/objects", 8))

0 commit comments

Comments
 (0)