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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 




On Fri, Sep 17 2021 at 03:10:12 AM -0400, Eric Sunshine <sunshine@xxxxxxxxxxxxxx> wrote:
`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).





[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux