[PATCH v2 5/5] checkpatch: Add warnings for using strn(cat|cpy)

Tom Rini trini at konsulko.com
Tue Apr 13 16:29:11 CEST 2021


On Thu, Mar 11, 2021 at 12:15:45AM -0500, Sean Anderson wrote:

> strn(cat|cpy) has a bad habit of not nul-terminating the destination,
> resulting in constructions like
> 
> 	strncpy(foo, bar, sizeof(foo) - 1);
> 	foo[sizeof(foo) - 1] = '\0';
> 
> However, it is very easy to forget about this behavior and accidentally
> leave a string unterminated. This has shown up in some recent coverity
> scans [1, 2] (including code recently touched by yours truly).
> 
> Fortunately, the guys at OpenBSD came up with strl(cat|cpy), which always
> nul-terminate strings. These functions are already in U-Boot, so we should
> encourage new code to use them instead of strn(cat|cpy).
> 
> [1] https://lists.denx.de/pipermail/u-boot/2021-March/442888.html
> [2] https://lists.denx.de/pipermail/u-boot/2021-January/438073.html
> 
> Signed-off-by: Sean Anderson <seanga2 at gmail.com>
> Reviewed-by: Simon Glass <sjg at chromium.org>

Applied to u-boot/master, thanks!

-- 
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 659 bytes
Desc: not available
URL: <https://lists.denx.de/pipermail/u-boot/attachments/20210413/13bfa119/attachment.sig>


More information about the U-Boot mailing list