Skip to content

Commit 0eeb3be

Browse files
derrickstoleegitster
authored andcommitted
unpack-trees: avoid array out-of-bounds error
The loop in warn_conflicted_path() that checks for the count of entries with the same path uses "i+count" for the array entry. However, the loop only verifies that the value of count is below the array size. Fix this by adding i to the condition. I hit this condition during a test of the in-tree sparse-checkout feature, so it is exercised by the end of the series. Signed-off-by: Derrick Stolee <[email protected]> [jc: readability fix] Signed-off-by: Junio C Hamano <[email protected]>
1 parent 5644ca2 commit 0eeb3be

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

unpack-trees.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -562,11 +562,11 @@ static int warn_conflicted_path(struct index_state *istate,
562562

563563
add_rejected_path(o, WARNING_SPARSE_UNMERGED_FILE, conflicting_path);
564564

565-
/* Find out how many higher stage entries at same path */
566-
while (++count < istate->cache_nr &&
567-
!strcmp(conflicting_path,
568-
istate->cache[i+count]->name))
569-
/* do nothing */;
565+
/* Find out how many higher stage entries are at same path */
566+
while ((++count) + i < istate->cache_nr &&
567+
!strcmp(conflicting_path, istate->cache[count + i]->name))
568+
; /* do nothing */
569+
570570
return count;
571571
}
572572

0 commit comments

Comments
 (0)