Re: [PATCH 3/6] refactored output function

Ildar Muslukhov <[email protected]>
Newsgroups org.kernel.vger.trinity
Message-ID <CAEGbLtvbREAxgQJL1bqMB-9NE3r=AkVEuT85XHFs3EQb7xJNfg@mail.gmail.com>
Sorry, just noticed this one.

I added it just for robustness in future, as the buffered output was
also working till the point when it got overflown. This way buffer
won't be overflown.

-Ildar

On Thu, Oct 10, 2013 at 11:20 AM, Dave Jones <[email protected]> wrote:
> Since applying this patch, coverity is picking up an out of bounds write.
> It looks like it can't happen, but I'm wondering why this code was
> done this way..
>
> hand-editted diff for clarity:
>
>  >      /* copy buffer, sans ANSI codes */
>  >      len = strlen(outputbuf);
>  > -    for (i = 0, j = 0; i < len; i++) {
>  > +    for (i = 0, j = 0; (i < len) && (i + 2 < BUFSIZE) && (j < BUFSIZE); i++) {
>  >              if (outputbuf[i] == ' ') {
>  >                      if (outputbuf[i + 2] == '1')
>  >                              i += 6; // ANSI_COLOUR
>  >                      else
>  >                              i += 3; // ANSI_RESET
>  >              } else {
>  >                      monobuf[j] = outputbuf[i];
>  >                      j++;
>  >              }
>  >      }
>  >      monobuf[j] = '\0';
>
> What's the intent behind this ?
> It seems redundant, as everything seems to work fine without this change.
>
>         Dave
>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.