[PATCH] link_alt_odb_entry: fix read over array bounds reported by valgrind
- From
Heiko Voigt <hvoigt@hvoigt.net>
- Date
- Jul 28, 2012, 15:46 UTC
- Message-ID
- <20120728154635.GB98893@book.hvoigt.net>
pfxlen can be longer than the path in objdir when relative_base contains the path to gits object directory.
Signed-off-by: Heiko Voigt <hvoigt@hvoigt.net> --- sha1_file.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/sha1_file.c b/sha1_file.c index 4ccaf7a..631d0dd 100644 --- a/sha1_file.c +++ b/sha1_file.c @@ -251,7 +251,7 @@ static int link_alt_odb_entry(const char * entry, int len, const char * relative const char *objdir = get_object_directory(); struct alternate_object_database *ent; struct alternate_object_database *alt; - int pfxlen, entlen; + int pfxlen, entlen, objdirlen; struct strbuf pathbuf = STRBUF_INIT; if (!is_absolute_path(entry) && relative_base) { @@ -298,7 +298,8 @@ static int link_alt_odb_entry(const char * entry, int len, const char * relative return -1; } } - if (!memcmp(ent->base, objdir, pfxlen)) { + objdirlen = strlen(objdir); + if (!memcmp(ent->base, objdir, pfxlen > objdirlen ? objdirlen : pfxlen)) { free(ent); return -1; }
-- 1.7.12.rc0.23.gc9a5ac4