1
0
mirror of https://github.com/git/git synced 2024-07-05 00:58:49 +00:00

sha1_name: fix segfault caused by invalid index access

The code to see if user input "git show :path" makes sense tried to access
the index without properly checking the array bound.

Signed-off-by: Markus Heidelberg <markus.heidelberg@web.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Markus Heidelberg 2010-02-28 16:49:15 +01:00 committed by Junio C Hamano
parent 64da6e20de
commit 77e8466fb9

View File

@ -992,6 +992,7 @@ static void diagnose_invalid_index_path(int stage,
pos = cache_name_pos(filename, namelen);
if (pos < 0)
pos = -pos - 1;
if (pos < active_nr) {
ce = active_cache[pos];
if (ce_namelen(ce) == namelen &&
!memcmp(ce->name, filename, namelen))
@ -999,6 +1000,7 @@ static void diagnose_invalid_index_path(int stage,
"Did you mean ':%d:%s'?",
filename, stage,
ce_stage(ce), filename);
}
/* Confusion between relative and absolute filenames? */
fullnamelen = namelen + strlen(prefix);
@ -1008,6 +1010,7 @@ static void diagnose_invalid_index_path(int stage,
pos = cache_name_pos(fullname, fullnamelen);
if (pos < 0)
pos = -pos - 1;
if (pos < active_nr) {
ce = active_cache[pos];
if (ce_namelen(ce) == fullnamelen &&
!memcmp(ce->name, fullname, fullnamelen))
@ -1015,6 +1018,7 @@ static void diagnose_invalid_index_path(int stage,
"Did you mean ':%d:%s'?",
fullname, filename,
ce_stage(ce), fullname);
}
if (!lstat(filename, &st))
die("Path '%s' exists on disk, but not in the index.", filename);