{"thread":{"id":"37033","subject":"[PATCH] sha1_file: avoid overrunning alternate object base string","startedAt":"2014-07-01T18:00:01Z","lastAt":"2014-07-01T18:00:01Z","messageCount":1,"participants":["René Scharfe"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"245246","messageId":"53B2F721.3080800@web.de","threadId":"37033","inReplyTo":null,"subject":"[PATCH] sha1_file: avoid overrunning alternate object base string","fromName":"René Scharfe","fromEmail":"l.s.r@web.de","sentAt":"2014-07-01T18:00:01Z","receivedAt":"2014-07-01T18:00:01Z","isPatch":true,"sender":{"key":"l.s.r@web.de","avatar":"https://avatars.githubusercontent.com/u/26122331?v=4"},"body":"While checking if a new alternate object database is a duplicate make\nsure that old and new base paths have the same length before comparing\nthem with memcmp.  This avoids overrunning the buffer of the existing\nentry if the new one is longer and it stops rejecting foobar/ after\nfoo/ was already added.\n\nSigned-off-by: Rene Scharfe <ls.r@web.de>\n---\n sha1_file.c | 3 ++-\n 1 file changed, 2 insertions(+), 1 deletion(-)\n\ndiff --git a/sha1_file.c b/sha1_file.c\nindex 8adab14..b7ad6c1 100644\n--- a/sha1_file.c\n+++ b/sha1_file.c\n@@ -315,7 +315,8 @@ static int link_alt_odb_entry(const char *entry, const char *relative_base, int\n \t * thing twice, or object directory itself.\n \t */\n \tfor (alt = alt_odb_list; alt; alt = alt->next) {\n-\t\tif (!memcmp(ent->base, alt->base, pfxlen)) {\n+\t\tif (pfxlen == alt->name - alt->base - 1 &&\n+\t\t    !memcmp(ent->base, alt->base, pfxlen)) {\n \t\t\tfree(ent);\n \t\t\treturn -1;\n \t\t}\n-- \n2.0.0\n"}]}