From: Thorsten Blum <thorsten.blum@linux.dev>
To: Andrew Morton <akpm@linux-foundation.org>,
Kees Cook <kees@kernel.org>, Andy Shevchenko <andy@kernel.org>
Cc: Thorsten Blum <thorsten.blum@linux.dev>,
linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org
Subject: [PATCH] string: use strnlen in strlcat
Date: Thu, 30 Apr 2026 22:50:53 +0200 [thread overview]
Message-ID: <20260430205050.400822-4-thorsten.blum@linux.dev> (raw)
Use strnlen() to limit the destination scan to the provided buffer size.
Remove the redundant comment.
Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
---
lib/string.c | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
diff --git a/lib/string.c b/lib/string.c
index b632c71df1a5..7b67e186d898 100644
--- a/lib/string.c
+++ b/lib/string.c
@@ -251,12 +251,11 @@ EXPORT_SYMBOL(strncat);
#ifndef __HAVE_ARCH_STRLCAT
size_t strlcat(char *dest, const char *src, size_t count)
{
- size_t dsize = strlen(dest);
+ size_t dsize = strnlen(dest, count);
size_t len = strlen(src);
size_t res = dsize + len;
- /* This would be a bug */
- BUG_ON(dsize >= count);
+ BUG_ON(dsize == count);
dest += dsize;
count -= dsize;
next reply other threads:[~2026-04-30 20:53 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-30 20:50 Thorsten Blum [this message]
2026-05-01 8:55 ` [PATCH] string: use strnlen in strlcat Andy Shevchenko
2026-05-02 8:37 ` Andy Shevchenko
2026-05-04 12:26 ` Manuel Ebner
2026-05-04 12:52 ` Andy Shevchenko
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=20260430205050.400822-4-thorsten.blum@linux.dev \
--to=thorsten.blum@linux.dev \
--cc=akpm@linux-foundation.org \
--cc=andy@kernel.org \
--cc=kees@kernel.org \
--cc=linux-hardening@vger.kernel.org \
--cc=linux-kernel@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