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

Re: [PATCH v5 2/2] pretty: colorize pattern matches in commit messages

From
Hamza Mahfooz <someguy@effective-light.com>
Date
Sep 17, 2021, 21:14 UTC
Message-ID
<WCKLZQ.YCP2HWKW7YBB2@effective-light.com>
In-Reply-To
<CAPig+cRfFZ=GAevJ0b9oBGTR8P3MnSg+R43ujSP0dZJL08riqA@mail.gmail.com>

On Fri, Sep 17 2021 at 03:10:12 AM -0400, Eric Sunshine <sunshine@sunshineco.com> wrote:

Show 17 quoted lines
> `buf` and `eol` seem like an accident waiting to happen...
> 
>>  +       line_color = opt->colors[GREP_COLOR_SELECTED];
>>  +       match_color = opt->colors[GREP_COLOR_MATCH_SELECTED];
>>  +
>>  +       while (grep_next_match(opt, buf, eol, ctx, &match, field, 
>> eflags)) {
>>  +               if (match.rm_so == match.rm_eo)
>>  +                       break;
>>  +
>>  +               strbuf_grow(sb, strlen(line_color) + 
>> strlen(match_color) +
>>  +                           (2 * strlen(GIT_COLOR_RESET)));
> 
> ... because strbuf_grow() may reallocate the underlying buffer, which
> means that `buf` and `eol` will end up pointing at freed memory, which
> will be accessed by the next call to grep_next_match().

I don't see how it's problematic, since `tmp_sb` isn't modified after `buf` is initialized (until strbuf_release() is called, of course).

Previous: Eric SunshineNext: Jeff King
Message 4 of 6 in “grep: refactor next_match() and match_one_pattern() for external use”
  1. 1/2 grep: refactor next_match() and match_one_pattern() for external useHamza Mahfooz, Sep 16, 2021
  2. 2/2 pretty: colorize pattern matches in commit messagesHamza Mahfooz, Sep 16, 2021
  3. Eric SunshineSep 17, 2021
  4. Hamza MahfoozSep 17, 2021
  5. Jeff KingSep 17, 2021
  6. Eric SunshineSep 17, 2021

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.