sha1_file: avoid overrunning alternate object base string

While checking if a new alternate object database is a duplicate make sure that old and new base paths have the same length before comparing them with memcmp. This avoids overrunning the buffer of the existing entry if the new one is longer and it stops rejecting foobar/ after foo/ was already added. Signed-off-by: Rene Scharfe <ls.r@web.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>

René Scharfe committed Jul 1, 2014 at 20:00 UTC 80b47854ca84abec991f6fff42dbeb6626588b87
1 file changed +2 -1
sha1_file.c
+2 -1
@@ -303,7 +303,8 @@ static int link_alt_odb_entry(const char *entry, const char *relative_base, int
303 * thing twice, or object directory itself.
304 */
305 for (alt = alt_odb_list; alt; alt = alt->next) {
306 - if (!memcmp(ent->base, alt->base, pfxlen)) {
306 + if (pfxlen == alt->name - alt->base - 1 &&
307 + !memcmp(ent->base, alt->base, pfxlen)) {
308 free(ent);
309 return -1;
310 }