git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH v3] diff: check range before dereferencing an array element

From
Junio C Hamano <gitster@pobox.com>
Date
Apr 29, 2025, 23:46 UTC
Message-ID
<xmqqy0vi350e.fsf@gitster.g>
In-Reply-To
<20250429233314.GA594987@coredump.intra.peff.net>
Jeff King <peff@peff.net> writes:
Show 11 quoted lines
> Ah, you're right. I was reading the offset check as "are we past the end
> of string" (guided by CodeQL's complaint), and if that were the case the
> logic would apply equally to all values we are checking.
>
> But that is not what is going on at all. The offset check is for "len -
> 1", and so is "do not do this one CR match for the final character of
> the string". And thus applying it elsewhere is wrong.
>
> And CodeQL's false positive is doubly wrong. We do not even need to say
> "the string is NUL-terminated, so it is OK in this case to look past the
> end-of-string". The check is not even a string bounds check at all.
Exactly.

That is what makes it hard to give a reasonable explanation in the log message, which I thought that Dscho did a much better job in this iteration.

Thanks.
Previous: Jeff King
Message 18 of 18 in “Range-check array index before access”
  1. 0/2 Range-check array index before accessJohannes Schindelin via GitGitGadget, Mar 26, 2025
  2. 1/2 diff: check range before dereferencing an array elementJohannes Schindelin via GitGitGadget, Mar 26, 2025
  3. Junio C HamanoMar 27, 2025
  4. Phillip WoodMar 27, 2025
  5. 2/2 read-cache: check range before dereferencing an array elementJohannes Schindelin via GitGitGadget, Mar 26, 2025
  6. Jeff KingMar 26, 2025
  7. 0/2 Range-check array index before accessJohannes Schindelin via GitGitGadget, Mar 27, 2025
  8. 1/2 diff: check range before dereferencing an array elementJohannes Schindelin via GitGitGadget, Mar 27, 2025
  9. Junio C HamanoMar 28, 2025
  10. 2/2 read-cache: check range before dereferencing an array elementJohannes Schindelin via GitGitGadget, Mar 27, 2025
  11. Jeff KingMar 28, 2025
  12. Junio C HamanoApr 11, 2025
  13. diff: check range before dereferencing an array elementJohannes Schindelin via GitGitGadget, Apr 29, 2025
  14. Junio C HamanoApr 29, 2025
  15. Jeff KingApr 29, 2025
  16. Junio C HamanoApr 29, 2025
  17. Jeff KingApr 29, 2025
  18. Junio C HamanoApr 29, 2025

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.