From: Theodore Ts'o <tytso@mit.edu>
To: Arnd Bergmann <arnd@arndb.de>
Cc: Xiongfeng Wang <wangxiongfeng2@huawei.com>,
Jan Kara <jack@suse.cz>,
Andreas Dilger <adilger.kernel@dilger.ca>,
linux-ext4@vger.kernel.org
Subject: Re: [PATCH] ext4: use strlcpy() instead of strncpy()
Date: Wed, 10 Jan 2018 18:01:31 -0500 [thread overview]
Message-ID: <20180110230131.GD6499@thunk.org> (raw)
In-Reply-To: <CAK8P3a1xGW+KmtaqQfuARTn2zwJ3J6fZrLqTchstJcvGPj_BEQ@mail.gmail.com>
On Wed, Jan 10, 2018 at 10:30:15PM +0100, Arnd Bergmann wrote:
> This warning option appears to be particularly good in finding code that
> is actually dangerous in case of an overflow, and generally using
> strscpy() improves either correctness and readability over strncpy(),
> I think it's worth leaving enabled globally.
>
> I have an experimental patch series to let you wrap the _Pragma("GCC
> diagnostic ingnored \"-Wstringop-truncation\"") directive in some
> nicer syntax. Would that work for you here?
Having a Pragma which silences errors is certainly better than
nothing, but what might be nice is to have a way of tagging a variable
or structure member function as "not guaranteed to be null
terminated". That would suppress warnings where strncpy is used to
set the character array, and add warnings if how the character array
is accessed without taking due care that it might not be
null-terminated.
Essentially all of the on-disk strings in ext4 are not NUL terminated
(or not necessarily NUL terminated). We either use an explicit length
(directory entries) or we use a fixed length character array (for the
things like the volume label, last error function, etc.)
Cheers,
- Ted
prev parent reply other threads:[~2018-01-10 23:01 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-01-09 8:58 [PATCH] ext4: use strlcpy() instead of strncpy() Xiongfeng Wang
2018-01-09 10:06 ` Jan Kara
2018-01-09 11:14 ` Xiongfeng Wang
2018-01-09 20:20 ` Theodore Ts'o
2018-01-10 21:30 ` Arnd Bergmann
2018-01-10 23:01 ` Theodore Ts'o [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=20180110230131.GD6499@thunk.org \
--to=tytso@mit.edu \
--cc=adilger.kernel@dilger.ca \
--cc=arnd@arndb.de \
--cc=jack@suse.cz \
--cc=linux-ext4@vger.kernel.org \
--cc=wangxiongfeng2@huawei.com \
/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.