Skip to content

Commit 95c1a79

Browse files
committed
Merge branch 'jk/info-alternates-fix' into maint
A regression fix for 2.11 that made the code to read the list of alternate object stores overrun the end of the string. * jk/info-alternates-fix: read_info_alternates: warn on non-trivial errors read_info_alternates: read contents into strbuf
2 parents 9fc7bc6 + f0f7beb commit 95c1a79

File tree

1 file changed

+11
-20
lines changed

1 file changed

+11
-20
lines changed

sha1_file.c

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,7 @@ static const char *parse_alt_odb_entry(const char *string,
422422
return end;
423423
}
424424

425-
static void link_alt_odb_entries(const char *alt, int len, int sep,
425+
static void link_alt_odb_entries(const char *alt, int sep,
426426
const char *relative_base, int depth)
427427
{
428428
struct strbuf objdirbuf = STRBUF_INIT;
@@ -451,28 +451,19 @@ static void link_alt_odb_entries(const char *alt, int len, int sep,
451451

452452
static void read_info_alternates(const char * relative_base, int depth)
453453
{
454-
char *map;
455-
size_t mapsz;
456-
struct stat st;
457454
char *path;
458-
int fd;
455+
struct strbuf buf = STRBUF_INIT;
459456

460457
path = xstrfmt("%s/info/alternates", relative_base);
461-
fd = git_open(path);
462-
free(path);
463-
if (fd < 0)
464-
return;
465-
if (fstat(fd, &st) || (st.st_size == 0)) {
466-
close(fd);
458+
if (strbuf_read_file(&buf, path, 1024) < 0) {
459+
warn_on_fopen_errors(path);
460+
free(path);
467461
return;
468462
}
469-
mapsz = xsize_t(st.st_size);
470-
map = xmmap(NULL, mapsz, PROT_READ, MAP_PRIVATE, fd, 0);
471-
close(fd);
472-
473-
link_alt_odb_entries(map, mapsz, '\n', relative_base, depth);
474463

475-
munmap(map, mapsz);
464+
link_alt_odb_entries(buf.buf, '\n', relative_base, depth);
465+
strbuf_release(&buf);
466+
free(path);
476467
}
477468

478469
struct alternate_object_database *alloc_alt_odb(const char *dir)
@@ -527,7 +518,7 @@ void add_to_alternates_file(const char *reference)
527518
if (commit_lock_file(lock))
528519
die_errno("unable to move new alternates file into place");
529520
if (alt_odb_tail)
530-
link_alt_odb_entries(reference, strlen(reference), '\n', NULL, 0);
521+
link_alt_odb_entries(reference, '\n', NULL, 0);
531522
}
532523
free(alts);
533524
}
@@ -540,7 +531,7 @@ void add_to_alternates_memory(const char *reference)
540531
*/
541532
prepare_alt_odb();
542533

543-
link_alt_odb_entries(reference, strlen(reference), '\n', NULL, 0);
534+
link_alt_odb_entries(reference, '\n', NULL, 0);
544535
}
545536

546537
/*
@@ -643,7 +634,7 @@ void prepare_alt_odb(void)
643634
if (!alt) alt = "";
644635

645636
alt_odb_tail = &alt_odb_list;
646-
link_alt_odb_entries(alt, strlen(alt), PATH_SEP, NULL, 0);
637+
link_alt_odb_entries(alt, PATH_SEP, NULL, 0);
647638

648639
read_info_alternates(get_object_directory(), 0);
649640
}

0 commit comments

Comments
 (0)