From: David Laight <david.laight.linux@gmail.com>
To: Kees Cook <kees@kernel.org>
Cc: Geert Uytterhoeven <geert@linux-m68k.org>,
Manuel Ebner <manuelebner@mailbox.org>,
andy.shevchenko@gmail.com, apw@canonical.com, corbet@lwn.net,
dwaipayanray1@gmail.com, joe@perches.com,
linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org,
lukas.bulwahn@gmail.com, skhan@linuxfoundation.org,
workflows@vger.kernel.org
Subject: Re: [PATCH 1/2] [PATCH 1/2] Doc: deprecated.rst: add strlcat()
Date: Mon, 11 May 2026 21:34:54 +0100 [thread overview]
Message-ID: <20260511213454.22f00bff@pumpkin> (raw)
In-Reply-To: <202605111206.ECA86141@keescook>
On Mon, 11 May 2026 12:07:38 -0700
Kees Cook <kees@kernel.org> wrote:
> On Mon, May 11, 2026 at 02:26:49PM +0100, David Laight wrote:
> > On Mon, 11 May 2026 13:40:55 +0200
> > Geert Uytterhoeven <geert@linux-m68k.org> wrote:
> >
> > > Hi Manuel,
> > >
> > > On Sun, 10 May 2026 at 18:52, Manuel Ebner <manuelebner@mailbox.org> wrote:
> > > > add strlcat and alternatives
> > >
> > > Thanks for your patch!
> > >
> > > > --- a/Documentation/process/deprecated.rst
> > > > +++ b/Documentation/process/deprecated.rst
> > > > @@ -162,6 +162,12 @@ if a source string is not NUL-terminated. The safe replacement is strscpy(),
> > > > though care must be given to any cases where the return value of strlcpy()
> > > > is used, since strscpy() will return negative errno values when it truncates.
> > > >
> > > > +strlcat()
> > > > +---------
> > > > +strlcat() must re-scan the destination string from the beginning on each
> > > > +call (O(n^2) behavior). Alternatives are seq_buf_puts(), seq_buf_printf(),
> > > > +snprintf() and scnprintf()
> > >
> > > The last two not only require the caller to keep track of the offset
> > > in the buffer, but also using "%s" when storing passed strings.
> >
> > Which also means they are significantly slower.
> > Mind you, some code has:
> > strlcat(buf, "\n", SIZE);
> > return strlen(buf);
> > which carefully scans the string twice.
> > Since the '\0' isn't always needed (eg 'show' functions), this can be:
> > len = strlen(buf);
> > buf[len] ='\n';
> > return len + 1;
> > Of course, the code could often easily get the length by other means.
>
> I think I'd prefer to only recommend using seq_buf API. Or for sysfs,
> sysfs_emit() as seq_buf hasn't been extended there yet.
True for the docs, but rather more work when you are just trying to
get rid of strcpy() and strcat() calls.
It can be hard working out whether you can use sysfs_emit() or not.
(And I recently failed to find where the PAGE_SIZE buffer is
actually allocated; I'm sure it should just be 4k.)
-- David
>
> -Kees
>
next prev parent reply other threads:[~2026-05-11 20:34 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-10 16:49 [PATCH 0/2] Doc, scripts: facilitate phaseout of strlcat Manuel Ebner
2026-05-10 16:52 ` [PATCH 1/2] [PATCH 1/2] Doc: deprecated.rst: add strlcat() Manuel Ebner
2026-05-11 11:40 ` Geert Uytterhoeven
2026-05-11 13:26 ` David Laight
2026-05-11 19:07 ` Kees Cook
2026-05-11 20:34 ` David Laight [this message]
2026-05-10 16:54 ` Manuel Ebner
2026-05-10 17:32 ` Randy Dunlap
2026-05-12 8:52 ` Jani Nikula
2026-05-12 10:43 ` Manuel Ebner
2026-05-12 13:57 ` David Laight
2026-05-10 16:56 ` [PATCH 2/2] scripts: checkpatch.pl: add warning for strlcat() Manuel Ebner
2026-05-10 17:31 ` Randy Dunlap
2026-05-11 12:12 ` Jonathan Corbet
2026-05-11 13:27 ` David Laight
2026-05-12 7:36 ` Manuel Ebner
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=20260511213454.22f00bff@pumpkin \
--to=david.laight.linux@gmail.com \
--cc=andy.shevchenko@gmail.com \
--cc=apw@canonical.com \
--cc=corbet@lwn.net \
--cc=dwaipayanray1@gmail.com \
--cc=geert@linux-m68k.org \
--cc=joe@perches.com \
--cc=kees@kernel.org \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=lukas.bulwahn@gmail.com \
--cc=manuelebner@mailbox.org \
--cc=skhan@linuxfoundation.org \
--cc=workflows@vger.kernel.org \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox