From: Tom Rini Date: Tue, 13 Apr 2021 10:29:11 -0400 Subject: [PATCH v2 5/5] checkpatch: Add warnings for using strn(cat|cpy) In-Reply-To: <20210311051545.1886333-6-seanga2@gmail.com> References: <20210311051545.1886333-1-seanga2@gmail.com> <20210311051545.1886333-6-seanga2@gmail.com> Message-ID: <20210413142911.GF1310@bill-the-cat> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de 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 > Reviewed-by: Simon Glass 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: