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

Re: [PATCH] pkt-line: don't check string length in packet_length()

From
Junio C Hamano <gitster@pobox.com>
Date
Jul 5, 2023, 20:33 UTC
Message-ID
<xmqq4jmiyu7s.fsf@gitster.g>
In-Reply-To
<32f41065-a78c-aa60-0d78-4dbfa8827b1a@web.de>
René Scharfe <l.s.r@web.de> writes:
Show 8 quoted lines
>> I do like the resulting code, but I feel a bit uneasy to sell this
>> change as "the code becomes more streamlined without losing safety".
>> It looks more like "this change is safe for our two callers; those
>> adding more callers in the future are better be very careful", no?
>
> With no way to enforce passing an array of a certain size to a function
> the only safe options I see are keeping the length check, using a macro
> or inlining the calculation.  Hmm.

We keep repeating "length check" because that is what the comment in the function says, but even if the caller has 4-byte, that 4-byte substring at the beginning is what it read from the untrusted side over the network. We should be checking if we have 4 hexadecimal length even if we are not running beyond the end of the buffer, no?

So it may be that the comment needs to be fixed more than the code.
Thanks.
Previous: René ScharfeNext: René Scharfe
Message 4 of 8 in “pkt-line: don't check string length in packet_length()”
  1. pkt-line: don't check string length in packet_length()René Scharfe, Jul 1, 2023
  2. Junio C HamanoJul 5, 2023
  3. René ScharfeJul 5, 2023
  4. Junio C HamanoJul 5, 2023
  5. René ScharfeJul 5, 2023
  6. Junio C HamanoJul 5, 2023
  7. René ScharfeJul 6, 2023
  8. pkt-line: add size parameter to packet_length()René Scharfe, Jul 7, 2023

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.