powerpc: use strscpy to replace strlcpy
authorJason Wang <wangborong@cdjrlc.com>
Sat, 7 Aug 2021 07:21:54 +0000 (15:21 +0800)
committerMichael Ellerman <mpe@ellerman.id.au>
Wed, 4 May 2022 09:37:44 +0000 (19:37 +1000)
The strlcpy should not be used because it doesn't limit the source
length. As linus says, it's a completely useless function if you
can't implicitly trust the source string - but that is almost always
why people think they should use it! All in all the BSD function
will lead some potential bugs.

But the strscpy doesn't require reading memory from the src string
beyond the specified "count" bytes, and since the return value is
easier to error-check than strlcpy()'s. In addition, the implementation
is robust to the string changing out from underneath it, unlike the
current strlcpy() implementation.

Thus, We prefer using strscpy instead of strlcpy.

Signed-off-by: Jason Wang <wangborong@cdjrlc.com>
Signed-off-by: Christophe Leroy <christophe.leroy@csgroup.eu>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Link: https://lore.kernel.org/r/20210807072154.64512-1-wangborong@cdjrlc.com
arch/powerpc/platforms/powermac/bootx_init.c

index d20ef35e6d9da18ebbf0b7627f81182b82314c8d..741aa5b89e55da96bf7c6a0f56c868018747f156 100644 (file)
@@ -243,7 +243,7 @@ static void __init bootx_scan_dt_build_strings(unsigned long base,
                DBG(" detected display ! adding properties names !\n");
                bootx_dt_add_string("linux,boot-display", mem_end);
                bootx_dt_add_string("linux,opened", mem_end);
-               strlcpy(bootx_disp_path, namep, sizeof(bootx_disp_path));
+               strscpy(bootx_disp_path, namep, sizeof(bootx_disp_path));
        }
 
        /* get and store all property names */