From: Rasmus Villemoes <rasmus.villemoes@prevas.dk>
To: Matthias Schiffer <matthias.schiffer@ew.tq-group.com>,
u-boot@lists.denx.de
Cc: Simon Glass <sjg@chromium.org>,
Sean Anderson <sean.anderson@seco.com>,
Masahisa Kojima <masahisa.kojima@linaro.org>,
u-boot-amlogic@groups.io, u-boot@ew.tq-group.com
Subject: Re: [PATCH 1/2] Revert "lib: string: Fix strlcpy return value", fix callers
Date: Mon, 7 Aug 2023 09:45:37 +0200 [thread overview]
Message-ID: <ff4e3500-6558-5800-9662-07a07d2e27bc@prevas.dk> (raw)
In-Reply-To: <20230714112451.144294-1-matthias.schiffer@ew.tq-group.com>
On 14/07/2023 13.24, Matthias Schiffer wrote:
> Both the Linux kernel and libbsd agree that strlcpy() should always
> return strlen(src) and not include the NUL termination. The incorrect
> U-Boot implementation makes it impossible to check the return value for
> truncation, and breaks code written with the usual implementation in
> mind (for example, fdtdec_add_reserved_memory() was subtly broken).
So while we're fixing non-standard string function behaviour, can we
_please_ finally fix strncpy() so it follows C/POSIX?
https://lore.kernel.org/u-boot/52bc92d4-8651-48df-3577-043aa2e16722@prevas.dk/
Note in particular the very last paragraph.
To rephrase and give a concrete example, what I'm worried about is us
importing some file system code that (correctly) uses strncpy() to fully
initialize some memory buffer, then writes that out to disk - but with
our crippled strncpy(), the result is potential garbage on-disk, which
both our own read implementation (which is likely also just copied) and
the kernel's may subsequently choke on.
Correctness first, please. If there are any performance problems, those
should be identified individually and perhaps rewritten to not use
strncpy() after verifying that not zeroing the tail is ok for that call
site.
Rasmus
next prev parent reply other threads:[~2023-08-07 7:45 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-07-14 11:24 [PATCH 1/2] Revert "lib: string: Fix strlcpy return value", fix callers Matthias Schiffer
2023-07-14 11:24 ` [PATCH 2/2] lib/charset: fix u16_strlcat() return value Matthias Schiffer
2023-08-09 1:39 ` Tom Rini
2023-08-02 10:06 ` [PATCH 1/2] Revert "lib: string: Fix strlcpy return value", fix callers Matthias Schiffer
2023-08-02 16:45 ` Tom Rini
2023-08-02 16:53 ` Simon Glass
2023-08-03 16:33 ` Sean Anderson
2023-08-07 7:45 ` Rasmus Villemoes [this message]
2023-08-09 17:18 ` Tom Rini
2023-08-09 1:39 ` Tom Rini
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=ff4e3500-6558-5800-9662-07a07d2e27bc@prevas.dk \
--to=rasmus.villemoes@prevas.dk \
--cc=masahisa.kojima@linaro.org \
--cc=matthias.schiffer@ew.tq-group.com \
--cc=sean.anderson@seco.com \
--cc=sjg@chromium.org \
--cc=u-boot-amlogic@groups.io \
--cc=u-boot@ew.tq-group.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox