MIPS: BCM47XX: Replace strlcpy with strscpy
authorJason Wang <wangborong@cdjrlc.com>
Mon, 6 Sep 2021 13:49:23 +0000 (21:49 +0800)
committerThomas Bogendoerfer <tsbogend@alpha.franken.de>
Thu, 16 Dec 2021 14:56:25 +0000 (15:56 +0100)
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: Thomas Bogendoerfer <tsbogend@alpha.franken.de>
arch/mips/bcm47xx/board.c

index 35266a70e22a3eeb475d9fbe7b09d346ee996fab..74113dcd86e0b2933cb2f4dd48c2dc4281231b5b 100644 (file)
@@ -345,7 +345,7 @@ void __init bcm47xx_board_detect(void)
 
        board_detected = bcm47xx_board_get_nvram();
        bcm47xx_board.board = board_detected->board;
-       strlcpy(bcm47xx_board.name, board_detected->name,
+       strscpy(bcm47xx_board.name, board_detected->name,
                BCM47XX_BOARD_MAX_NAME);
 }