From: Junio C Hamano <gitster@pobox.com>
To: Jeff King <peff@peff.net>
Cc: Johannes Schindelin via GitGitGadget <gitgitgadget@gmail.com>,
git@vger.kernel.org,
Johannes Schindelin <johannes.schindelin@gmx.de>
Subject: Re: [PATCH v2 2/2] read-cache: check range before dereferencing an array element
Date: Fri, 11 Apr 2025 07:50:37 -0700 [thread overview]
Message-ID: <xmqq7c3qoipu.fsf@gitster.g> (raw)
In-Reply-To: <20250328054953.GA3590654@coredump.intra.peff.net> (Jeff King's message of "Fri, 28 Mar 2025 01:49:53 -0400")
Jeff King <peff@peff.net> writes:
> On Thu, Mar 27, 2025 at 11:05:57AM +0000, Johannes Schindelin via GitGitGadget wrote:
>
>> From: Johannes Schindelin <johannes.schindelin@gmx.de>
>>
>> Before accessing an array element at a given index, we should make sure
>> that the index is within the desired bounds, otherwise it makes little
>> sense to access the array element in the first place.
>>
>> In this instance, testing whether `ce->name[common]` is the trailing NUL
>> byte is technically different from testing whether `common` is within
>> the bounds of `previous_name`. It is also redundant, as the range-check
>> guarantees that `previous_name->buf[common]` cannot be NUL and therefore
>> the condition `ce->name[common] == previous_name->buf[common]` would not
>> be met if `ce->name[common]` evaluated to NUL.
>>
>> However, in the interest of reducing the cognitive load to reason about
>> the correctness of this loop (so that I can focus on interesting
>> projects again), I'll simply move the range-check to the beginning of
>> the loop condition and keep the redundant NUL check.
>
> Thanks, I think this explanation works, and the patch looks fine. (I
> didn't dig deeply into patch 1, but I agree with Junio's analysis that
> it is also a false positive).
I think (1) working around a rare false positive to help us use an
otherwise mostly useful tool is a worthy thing to do, and (2) when
we need to make a workaround for a false positive, we should mark a
change to do so as such. And I agree with you that this step in the
updated form, both the change in the patch and the proposed log
message do their job.
Thanks, both. Will mark this one for 'next'.
Note that I think [1/2] needs similar updates relative to the
initial iteration, but since these two patches do not depend on each
other, I'll fast track this step without waiting updates to the
other one.
next prev parent reply other threads:[~2025-04-11 14:50 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-03-26 17:26 [PATCH 0/2] Range-check array index before access Johannes Schindelin via GitGitGadget
2025-03-26 17:26 ` [PATCH 1/2] diff: check range before dereferencing an array element Johannes Schindelin via GitGitGadget
2025-03-27 11:01 ` Junio C Hamano
2025-03-27 14:59 ` Phillip Wood
2025-03-26 17:26 ` [PATCH 2/2] read-cache: " Johannes Schindelin via GitGitGadget
2025-03-26 18:02 ` Jeff King
2025-03-27 11:05 ` [PATCH v2 0/2] Range-check array index before access Johannes Schindelin via GitGitGadget
2025-03-27 11:05 ` [PATCH v2 1/2] diff: check range before dereferencing an array element Johannes Schindelin via GitGitGadget
2025-03-28 2:54 ` Junio C Hamano
2025-03-27 11:05 ` [PATCH v2 2/2] read-cache: " Johannes Schindelin via GitGitGadget
2025-03-28 5:49 ` Jeff King
2025-04-11 14:50 ` Junio C Hamano [this message]
2025-04-29 11:37 ` [PATCH v3] diff: " Johannes Schindelin via GitGitGadget
2025-04-29 19:39 ` Junio C Hamano
2025-04-29 21:58 ` Jeff King
2025-04-29 22:37 ` Junio C Hamano
2025-04-29 23:33 ` Jeff King
2025-04-29 23:46 ` Junio C Hamano
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=xmqq7c3qoipu.fsf@gitster.g \
--to=gitster@pobox.com \
--cc=git@vger.kernel.org \
--cc=gitgitgadget@gmail.com \
--cc=johannes.schindelin@gmx.de \
--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.
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 NNTP newsgroup(s).