All of lore.kernel.org
 help / color / mirror / Atom feed
From: Len Baker <len.baker@gmx.com>
To: Andy Shevchenko <andy.shevchenko@gmail.com>
Cc: Len Baker <len.baker@gmx.com>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Phil Reid <preid@electromag.com.au>,
	Geert Uytterhoeven <geert@linux-m68k.org>,
	dri-devel <dri-devel@lists.freedesktop.org>,
	"open list:FRAMEBUFFER LAYER" <linux-fbdev@vger.kernel.org>,
	linux-staging@lists.linux.dev,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v2 1/3] staging/fbtft: Remove all strcpy() uses
Date: Sun, 25 Jul 2021 15:58:44 +0200	[thread overview]
Message-ID: <20210725135844.GA1953@titan> (raw)
In-Reply-To: <CAHp75Vd+ZM_yO6CU_6oJieePMt00Sp6oKEU2+QEyZxLDg5PN8A@mail.gmail.com>

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@gmx.com> 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

WARNING: multiple messages have this Message-ID (diff)
From: Len Baker <len.baker@gmx.com>
To: Andy Shevchenko <andy.shevchenko@gmail.com>
Cc: "open list:FRAMEBUFFER LAYER" <linux-fbdev@vger.kernel.org>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	linux-staging@lists.linux.dev,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
	dri-devel <dri-devel@lists.freedesktop.org>,
	Len Baker <len.baker@gmx.com>,
	Geert Uytterhoeven <geert@linux-m68k.org>,
	Phil Reid <preid@electromag.com.au>
Subject: Re: [PATCH v2 1/3] staging/fbtft: Remove all strcpy() uses
Date: Sun, 25 Jul 2021 15:58:44 +0200	[thread overview]
Message-ID: <20210725135844.GA1953@titan> (raw)
In-Reply-To: <CAHp75Vd+ZM_yO6CU_6oJieePMt00Sp6oKEU2+QEyZxLDg5PN8A@mail.gmail.com>

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@gmx.com> 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

  reply	other threads:[~2021-07-25 13:59 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-24 15:14 [PATCH v2 0/3] Remove all strcpy() uses Len Baker
2021-07-24 15:14 ` Len Baker
2021-07-24 15:14 ` [PATCH v2 1/3] staging/fbtft: " Len Baker
2021-07-24 15:14   ` Len Baker
2021-07-24 20:21   ` Andy Shevchenko
2021-07-24 20:21     ` Andy Shevchenko
2021-07-24 20:21     ` Andy Shevchenko
2021-07-25 13:58     ` Len Baker [this message]
2021-07-25 13:58       ` Len Baker
2021-07-25 18:51       ` Andy Shevchenko
2021-07-25 18:51         ` Andy Shevchenko
2021-07-25 18:51         ` Andy Shevchenko
2021-07-31 13:43         ` Len Baker
2021-07-24 15:14 ` [PATCH v2 2/3] staging/fbtft: Remove unnecessary variable initialization Len Baker
2021-07-24 15:14   ` Len Baker
2021-07-24 15:14 ` [PATCH v2 3/3] staging/fbtft: Fix braces coding style Len Baker
2021-07-24 15:14   ` Len Baker
2021-07-24 18:01   ` Geert Uytterhoeven
2021-07-24 18:01     ` Geert Uytterhoeven
2021-07-24 18:01     ` Geert Uytterhoeven
2021-07-25 14:02     ` Len Baker
2021-07-25 14:02       ` Len Baker

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210725135844.GA1953@titan \
    --to=len.baker@gmx.com \
    --cc=andy.shevchenko@gmail.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=geert@linux-m68k.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-fbdev@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-staging@lists.linux.dev \
    --cc=preid@electromag.com.au \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.