string: use strnlen in strlcat
Subsystems (2)
PATCH 1/1 string: use strnlen in strlcat
Use strnlen() to limit the destination scan to the provided buffer size. Remove the redundant comment.
--- lib/string.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
lib/string.c +2 -3
@@ -251,12 +251,11 @@ EXPORT_SYMBOL(strncat);#ifndef __HAVE_ARCH_STRLCATsize_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;
Quoted 3 lines · Thorsten Blum
Use
strnlen()to limit the destination scan to the provided buffer size. Remove the redundant comment.
Please, do not spend time on amending strlcat(). This function must die. Instead, convert current users to use alternative ways.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Quoted 7 lines · Andy Shevchenko
Quoted 3 lines · Thorsten Blum
Use
strnlen()to limit the destination scan to the provided buffer size. Remove the redundant comment.Please, do not spend time on amending
strlcat(). This function must die. Instead, convert current users to use alternative ways.
Note, there is a patch by Kees to address this in partitions framework (vast of the users of strlcat() in the kernel). Not sure if it's already pending in Linux Next or not yet.
I have done a simple one in ACPI recently (in upstream already I believe). So, you can use those two examples and continue killing strlcat().
Signature · 2 lines
With Best Regards, Andy Shevchenko
Quoted 10 lines · Andy Shevchenko
Quoted 8 lines · Andy Shevchenko
Quoted 3 lines · Thorsten Blum
Use
strnlen()to limit the destination scan to the provided buffer size. Remove the redundant comment.Please, do not spend time on amending
strlcat(). This function must die. Instead, convert current users to use alternative ways.
Quoted 6 lines
Note, there is a patch by Kees to address this in partitions framework (vast of the users of
strlcat()in the kernel). Not sure if it's already pending in Linux Next or not yet.I have done a simple one in ACPI recently (in upstream already I believe). So, you can use those two examples and continue killing
strlcat().
Hi,
i would like to add this to the file Documentation/process/deprecated.rst. Does right after strlcpy() make sense?
Could you point me to the examples?
Thanks
Manuel
Quoted 12 lines · Manuel Ebner
Quoted 11 lines · Andy Shevchenko
Quoted 5 lines · Andy Shevchenko
On Thu, Apr 30, 2026 at 11:53 PM Thorsten Blum <[email protected]> wrote:
Please, do not spend time on amending
strlcat(). This function must die. Instead, convert current users to use alternative ways.Note, there is a patch by Kees to address this in partitions framework (vast of the users of
strlcat()in the kernel). Not sure if it's already pending in Linux Next or not yet.
Quoted 5 lines
Quoted 2 lines
I have done a simple one in ACPI recently (in upstream already I believe). So, you can use those two examples and continue killing
strlcat().i would like to add this to the file
Documentation/process/deprecated.rst. Does right afterstrlcpy()make sense?
Yes, please.
Quoted 1 line
Could you point me to the examples?
c2d466b9fe19 ("block: partitions: Replace pp_buf with struct seq_buf") 36cb728754ea ("ACPI: processor: idle: Replace strlcat() with better alternative")
Signature · 2 lines
With Best Regards, Andy Shevchenko