[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <CADmuW3UZ9+9DmXPEyitgn_8Rg7U-iGvV-wJ-ug7eW84JSti47g@mail.gmail.com>
Date: Thu, 15 Jun 2023 14:09:13 -0400
From: Azeem Shaikh <azeemshaikh38@...il.com>
To: Kees Cook <keescook@...omium.org>
Cc: Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
linux-hardening@...r.kernel.org, linux-usb@...r.kernel.org,
linux-kernel@...r.kernel.org,
Albert Briscoe <albertsbriscoe@...il.com>,
Benjamin Tissoires <benjamin.tissoires@...hat.com>,
Andrzej Pietrasiewicz <andrzej.p@...labora.com>
Subject: Re: [PATCH] usb: gadget: function: printer: Replace strlcpy with strscpy
On Wed, Jun 14, 2023 at 1:51 PM Kees Cook <keescook@...omium.org> wrote:
>
> On Wed, Jun 14, 2023 at 10:12:14AM -0400, Azeem Shaikh wrote:
> > On Tue, Jun 13, 2023 at 3:30 PM Kees Cook <keescook@...omium.org> wrote:
> > >
> > > On Tue, Jun 13, 2023 at 12:43:41AM +0000, Azeem Shaikh wrote:
> > [...]
> > > > - result = strlcpy(page, opts->pnp_string, PAGE_SIZE);
> > > > - if (result >= PAGE_SIZE) {
> > > > + result = strscpy(page, opts->pnp_string, PAGE_SIZE);
> > > > + if (result == -E2BIG) {
> > >
> > > I think "< 1" might be a better test here.
> >
> > Curious, why "< 1" instead of "< 0"?
> >
> > > > result = PAGE_SIZE;
> > > > } else if (page[result - 1] != '\n' && result + 1 < PAGE_SIZE) {
>
> It's for this case above where "result" may be used in an array index,
> and if it's 0 or less, there will be a negative array index (due to the "-
> 1"). So, here, it needs to be "< 1" instead of the more traditional "< 0".
>
Makes sense. Sent out a v2.
Powered by blists - more mailing lists