All of lore.kernel.org
 help / color / mirror / Atom feed
From: Tom Rini <trini@konsulko.com>
To: u-boot@lists.denx.de
Subject: [PATCH v2 5/5] checkpatch: Add warnings for using strn(cat|cpy)
Date: Tue, 13 Apr 2021 10:29:11 -0400	[thread overview]
Message-ID: <20210413142911.GF1310@bill-the-cat> (raw)
In-Reply-To: <20210311051545.1886333-6-seanga2@gmail.com>

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@gmail.com>
> Reviewed-by: Simon Glass <sjg@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>

      parent reply	other threads:[~2021-04-13 14:29 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-11  5:15 [PATCH v2 0/5] string: strl(cat|cpy) Sean Anderson
2021-03-11  5:15 ` [PATCH v2 1/5] lib: string: Fix strlcpy return value Sean Anderson
2021-03-25  0:38   ` Simon Glass
2021-03-25  0:54     ` Sean Anderson
2021-03-25  2:40       ` Simon Glass
2021-03-25  0:53   ` Sean Anderson
2021-04-13 14:28   ` Tom Rini
2021-03-11  5:15 ` [PATCH v2 2/5] lib: string: Implement strlcat Sean Anderson
2021-03-25  0:38   ` Simon Glass
2021-04-13 14:28   ` Tom Rini
2021-03-11  5:15 ` [PATCH v2 3/5] test: Add test for strlcat Sean Anderson
2021-03-25  0:38   ` Simon Glass
2021-04-13 14:29   ` Tom Rini
2021-03-11  5:15 ` [PATCH v2 4/5] fastboot: Fix possible buffer overrun Sean Anderson
2021-04-13 14:29   ` Tom Rini
2021-03-11  5:15 ` [PATCH v2 5/5] checkpatch: Add warnings for using strn(cat|cpy) Sean Anderson
2021-03-25  0:38   ` Simon Glass
2021-04-13 14:29   ` Tom Rini [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210413142911.GF1310@bill-the-cat \
    --to=trini@konsulko.com \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.