]> git.ipfire.org Git - thirdparty/git.git/commitdiff
unpack-trees: avoid array out-of-bounds error
authorDerrick Stolee <dstolee@microsoft.com>
Thu, 7 May 2020 13:17:33 +0000 (13:17 +0000)
committerJunio C Hamano <gitster@pobox.com>
Fri, 8 May 2020 18:01:27 +0000 (11:01 -0700)
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>
[jc: readability fix]
Signed-off-by: Junio C Hamano <gitster@pobox.com>
unpack-trees.c

index b43f3e775ad858f16f14078e798ea5718316bf49..4bd0726eea3809daf60bfa55419a040998f8f264 100644 (file)
@@ -562,11 +562,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 &&
-              !strcmp(conflicting_path,
-                      istate->cache[i+count]->name))
-               /* do nothing */;
+       /* Find out how many higher stage entries are at same path */
+       while ((++count) + i < istate->cache_nr &&
+              !strcmp(conflicting_path, istate->cache[count + i]->name))
+               ; /* do nothing */
+
        return count;
 }