Use strnlen() to limit the destination scan to the provided buffer size. Remove the redundant comment.
Signed-off-by: Thorsten Blum <[email protected]> --- 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;

