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

Re: Re* [PATCH v7 1/1] sideband: highlight keywords in remote sideband output

From
Jeff King <peff@peff.net>
Date
Aug 18, 2018, 23:22 UTC
Message-ID
<20180818232220.GA24533@sigill.intra.peff.net>
In-Reply-To
<xmqqa7pjabvn.fsf@gitster-ct.c.googlers.com>
On Sat, Aug 18, 2018 at 09:16:28AM -0700, Junio C Hamano wrote:
Show 18 quoted lines
> -- >8 --
> Subject: [PATCH] sideband: do not read beyond the end of input
> 
> The caller of maybe_colorize_sideband() gives a counted buffer
> <src, n>, but the callee checked src[] as if it were a NUL terminated
> buffer.  If src[] had all isspace() bytes in it, we would have made
> n negative, and then
> 
>  (1) made number of strncasecmp() calls to see if the remaining
>      bytes in src[] matched keywords, reading beyond the end of the
>      array (this actually happens even if n does not go negative),
>      and/or
> 
>  (2) called strbuf_add() with negative count, most likely triggering
>      the "you want to use way too much memory" error due to unsigned
>      integer overflow.
> 
> Fix both issues by making sure we do not go beyond &src[n].

Thanks. I've been sporadically seeing "fatal: you want to use way too much memory" the last few days while running 'next', and finally managed to catch a reproducible case. This patch definitely fixes it.

> In the longer term we may want to accept size_t as parameter for
> clarity (even though we know that a sideband message we are painting
> typically would fit on a line on a terminal and int is sufficient).
> Write it down as a NEEDSWORK comment.

This "typically" made me nervous about what happens in the non-typical case, but I think we can say something even stronger: the length comes from a pktline, so the maximum is less than 16 bits. I wondered if we might ever call this on the accumulated string from multiple sidebands, but it doesn't look like it.

-Peff
Previous: Junio C HamanoNext: Junio C Hamano
Message 9 of 17 in “sideband: highlight keywords in remote sideband output”
  1. 0/1 sideband: highlight keywords in remote sideband outputHan-Wen Nienhuys, Aug 7, 2018
  2. 1/1 sideband: highlight keywords in remote sideband outputHan-Wen Nienhuys, Aug 7, 2018
  3. Junio C HamanoAug 17, 2018
  4. Re* [PATCH v7 1/1] sideband: highlight keywords in remote sideband outputJunio C Hamano, Aug 17, 2018
  5. Jonathan NiederAug 18, 2018
  6. Junio C HamanoAug 18, 2018
  7. Junio C HamanoAug 18, 2018
  8. Junio C HamanoAug 18, 2018
  9. Jeff KingAug 18, 2018
  10. Junio C HamanoAug 20, 2018
  11. Han-Wen NienhuysAug 20, 2018
  12. Han-Wen NienhuysAug 20, 2018
  13. Junio C HamanoAug 20, 2018
  14. Jonathan NiederAug 18, 2018
  15. Junio C HamanoAug 18, 2018
  16. Junio C HamanoAug 7, 2018
  17. Han-Wen NienhuysAug 8, 2018

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.