Re: [PATCH v2 1/3] staging/fbtft: Remove all strcpy() uses

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

 



Hi,

On Sat, Jul 24, 2021 at 11:21:04PM +0300, Andy Shevchenko wrote:
> On Sat, Jul 24, 2021 at 7:05 PM Len Baker <len.baker@xxxxxxx> wrote:
> >
> > strcpy() performs no bounds checking on the destination buffer. This
> > could result in linear overflows beyond the end of the buffer, leading
> > to all kinds of misbehaviors. The safe replacement is strscpy() but in
> > this case it is simpler to use the "%*ph" format specifier.
>
> ...
>
> > -       char msg[128];
>
> 128 / 4 = 32. So, this buffer is enough to debug print only up to 32
> bytes. Hence %*ph replacement won't cut output earlier than requested.

I'm sorry, but I don't understand what you are trying to explain. Moreover,
with the "0x%02X " in the sprintf followed by the strcat, the msg buffer can
print 128/5 values (25 hex values).

The %*ph replacement can print up to 64 bytes, so I don't see any problem
here.

>
> ...
>
> > +                       for (j = i + 1; par->init_sequence[j] >= 0; j++);
>
> Why is i + 1 initial for the j? You may rather access the 'i + 1 +
> j'th element in the array...
>
> ...
>
> > +                                     par->init_sequence[i], j - i - 1,
>
> ...and get rid of the ' - i -1' part here.

Yes, it was the first idea but I prefer this method since we save aritmethic
operations. In other words, if I use what you suggest, the index for
par->init_sequence is calculated as a "sum" every iteration. But if the
performance is not an issue and you believe that the above is more clear, I
have no problem. What do you prefer?

Thanks,
Len




[Index of Archives]     [Linux DRI Users]     [Linux Intel Graphics]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [XFree86]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [XFree86]
  Powered by Linux