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, 22:27 UTC
Message-ID
<xmqqsfa2uh83.fsf@gitster.g>
In-Reply-To
<6f984150-5a98-b2b8-1791-b101f5953b7a@web.de>
René Scharfe <l.s.r@web.de> writes:
> Sure, that's done.  If any of the four characters is not a hexadecimal
> digit then packet_length() returns a negative value, before and after
> the change.
Ah, it is the beauty of hexval[] table ;-)

So as long as we are sure that we are not running beyond the end of the buffer, we are OK. And as I already said, I think "this change is safe for our two callers; those adding more callers in the future are better be very careful" is probably good enough for this one.

hex.h:hex2chr() says "don't run over the end of short strings", but as far as I can see it does not check any such thing; find a page of memory, whose next page is unmapped, and pointing *s at the last byte of that page and calling it will happily run over the end and would cause SIGBUS. The function assumes that such a short string is always NUL terminated, which is not a great way to guarantee that we do not run over the end of strings.

Previous: René ScharfeNext: René Scharfe
Message 6 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.