[PATCH 01/10] unpack-trees: avoid array out-of-bounds error
- From
Derrick Stolee via GitGitGadget <gitgitgadget@gmail.com>
- Date
- May 7, 2020, 13:17 UTC
- Message-ID
- <5bfe3f3fc8a99b3d4fdd4286da17cd935090c614.1588857462.git.gitgitgadget@gmail.com>
- In-Reply-To
- <pull.627.git.1588857462.gitgitgadget@gmail.com>
From: Derrick Stolee <dstolee@microsoft.com>
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 <dstolee@microsoft.com> --- unpack-trees.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/unpack-trees.c b/unpack-trees.c index 9a3ccd9d083..4f880f2da90 100644 --- a/unpack-trees.c +++ b/unpack-trees.c @@ -563,10 +563,11 @@ static int warn_conflicted_path(struct index_state *istate, add_rejected_path(o, WARNING_SPARSE_UNMERGED_FILE, conflicting_path); /* Find out how many higher stage entries at same path */ - while (++count < istate->cache_nr && + while (i + ++count < istate->cache_nr && !strcmp(conflicting_path, istate->cache[i+count]->name)) /* do nothing */; + return count; }
-- gitgitgadget