From: Junio C Hamano <gitster@pobox.com>
To: "Derrick Stolee via GitGitGadget" <gitgitgadget@gmail.com>
Cc: git@vger.kernel.org, newren@gmaill.com, peff@peff.net,
me@ttaylorr.com, jrnieder@gmail.com,
Derrick Stolee <dstolee@microsoft.com>
Subject: Re: [PATCH 01/10] unpack-trees: avoid array out-of-bounds error
Date: Thu, 07 May 2020 15:27:28 -0700 [thread overview]
Message-ID: <xmqqk11n2xf3.fsf@gitster.c.googlers.com> (raw)
In-Reply-To: <5bfe3f3fc8a99b3d4fdd4286da17cd935090c614.1588857462.git.gitgitgadget@gmail.com> (Derrick Stolee via GitGitGadget's message of "Thu, 07 May 2020 13:17:33 +0000")
"Derrick Stolee via GitGitGadget" <gitgitgadget@gmail.com> writes:
> 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 */;
Eek. Yes, it is obvious that the original is wrong once you point
it out. But "i + ++count" looks like a line noise, and funny way
that lines are wrapped in the original does not help X-<.
We may want to fix the style and the grammar while we are at it,
perhaps like the attached.
In any case, thanks for a fix.
unpack-trees.c | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/unpack-trees.c b/unpack-trees.c
index 6bbf58d28e..c38938d96c 100644
--- a/unpack-trees.c
+++ b/unpack-trees.c
@@ -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;
}
next prev parent reply other threads:[~2020-05-07 22:27 UTC|newest]
Thread overview: 32+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-05-07 13:17 [PATCH 00/10] [RFC] In-tree sparse-checkout definitions Derrick Stolee via GitGitGadget
2020-05-07 13:17 ` [PATCH 01/10] unpack-trees: avoid array out-of-bounds error Derrick Stolee via GitGitGadget
2020-05-07 22:27 ` Junio C Hamano [this message]
2020-05-08 12:19 ` Derrick Stolee
2020-05-08 15:09 ` Junio C Hamano
2020-05-20 16:32 ` Elijah Newren
2020-05-07 13:17 ` [PATCH 02/10] sparse-checkout: move code from builtin Derrick Stolee via GitGitGadget
2020-05-07 13:17 ` [PATCH 03/10] sparse-checkout: move code from unpack-trees.c Derrick Stolee via GitGitGadget
2020-05-07 13:17 ` [PATCH 04/10] sparse-checkout: allow in-tree definitions Derrick Stolee via GitGitGadget
2020-05-07 22:58 ` Junio C Hamano
2020-05-08 15:40 ` Derrick Stolee
2020-05-20 17:52 ` Elijah Newren
2020-06-17 23:07 ` Elijah Newren
2020-06-18 8:18 ` Son Luong Ngoc
2020-05-07 13:17 ` [PATCH 05/10] sparse-checkout: automatically update in-tree definition Derrick Stolee via GitGitGadget
2020-05-20 16:28 ` Elijah Newren
2020-05-07 13:17 ` [PATCH 06/10] sparse-checkout: use oidset to prevent repeat blobs Derrick Stolee via GitGitGadget
2020-05-20 16:40 ` Elijah Newren
2020-05-21 3:49 ` Elijah Newren
2020-05-21 17:54 ` Derrick Stolee
2020-05-07 13:17 ` [PATCH 07/10] sparse-checkout: define in-tree dependencies Derrick Stolee via GitGitGadget
2020-05-20 18:10 ` Elijah Newren
2020-05-30 17:26 ` Elijah Newren
2020-05-07 13:17 ` [PATCH 08/10] Makefile: skip git-gui if dir is missing Derrick Stolee via GitGitGadget
2020-05-07 13:17 ` [PATCH 09/10] Makefile: disable GETTEXT when 'po' " Derrick Stolee via GitGitGadget
2020-05-07 13:17 ` [PATCH 10/10] .sparse: add in-tree sparse-checkout for Git Derrick Stolee via GitGitGadget
2020-05-20 17:38 ` [PATCH 00/10] [RFC] In-tree sparse-checkout definitions Elijah Newren
2020-06-17 23:14 ` Elijah Newren
2020-06-18 1:42 ` Derrick Stolee
2020-06-18 1:59 ` Elijah Newren
2020-06-18 3:01 ` Derrick Stolee
2020-06-18 5:03 ` Elijah Newren
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=xmqqk11n2xf3.fsf@gitster.c.googlers.com \
--to=gitster@pobox.com \
--cc=dstolee@microsoft.com \
--cc=git@vger.kernel.org \
--cc=gitgitgadget@gmail.com \
--cc=jrnieder@gmail.com \
--cc=me@ttaylorr.com \
--cc=newren@gmaill.com \
--cc=peff@peff.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).