Skip to content

Commit c7cddc1

Browse files
René Scharfegitster
authored andcommitted
merge: fix out-of-bounds memory access
The parameter n of unpack_callback() can have a value of up to MAX_UNPACK_TREES. The check at the top of unpack_trees() (its only (indirect) caller) makes sure it cannot exceed this limit. unpack_callback() passes it and the array src to unpack_nondirectories(), which has this loop: for (i = 0; i < n; i++) { /* ... */ src[i + o->merge] = o->df_conflict_entry; o->merge can be 0 or 1, so unpack_nondirectories() potentially accesses the array src at index MAX_UNPACK_TREES. This patch makes it big enough. Reported-by: Ingo Molnar <[email protected]> Signed-off-by: René Scharfe <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 915308b commit c7cddc1

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

unpack-trees.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -240,8 +240,11 @@ static struct cache_entry *create_ce_entry(const struct traverse_info *info, con
240240
return ce;
241241
}
242242

243-
static int unpack_nondirectories(int n, unsigned long mask, unsigned long dirmask, struct cache_entry *src[5],
244-
const struct name_entry *names, const struct traverse_info *info)
243+
static int unpack_nondirectories(int n, unsigned long mask,
244+
unsigned long dirmask,
245+
struct cache_entry **src,
246+
const struct name_entry *names,
247+
const struct traverse_info *info)
245248
{
246249
int i;
247250
struct unpack_trees_options *o = info->data;
@@ -291,7 +294,7 @@ static int unpack_nondirectories(int n, unsigned long mask, unsigned long dirmas
291294

292295
static int unpack_callback(int n, unsigned long mask, unsigned long dirmask, struct name_entry *names, struct traverse_info *info)
293296
{
294-
struct cache_entry *src[5] = { NULL, };
297+
struct cache_entry *src[MAX_UNPACK_TREES + 1] = { NULL, };
295298
struct unpack_trees_options *o = info->data;
296299
const struct name_entry *p = names;
297300

0 commit comments

Comments
 (0)