From: "Theodore Y. Ts'o" <tytso@mit.edu>
To: Kang Wenlin <wenlin.kang@windriver.com>
Cc: adilger.kernel@dilger.ca, linux-ext4@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH] ext4: fix -Wstringop-truncation warnings
Date: Tue, 15 Dec 2020 23:20:18 -0500 [thread overview]
Message-ID: <X9mLAlWbjrU5iE+r@mit.edu> (raw)
In-Reply-To: <20201112093324.8052-1-wenlin.kang@windriver.com>
On Thu, Nov 12, 2020 at 05:33:24PM +0800, Kang Wenlin wrote:
> From: Wenlin Kang <wenlin.kang@windriver.com>
>
> The strncpy() function may create a unterminated string,
> use strscpy_pad() instead.
>
> This fixes the following warning:
>
> fs/ext4/super.c: In function '__save_error_info':
> fs/ext4/super.c:349:2: warning: 'strncpy' specified bound 32 equals destination size [-Wstringop-truncation]
> strncpy(es->s_last_error_func, func, sizeof(es->s_last_error_func));
> ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> fs/ext4/super.c:353:3: warning: 'strncpy' specified bound 32 equals destination size [-Wstringop-truncation]
> strncpy(es->s_first_error_func, func,
> ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> sizeof(es->s_first_error_func));
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
What compiler are you using? s_last_error_func is defined to not
necessarily be NUL terminated. So strscpy_pad() is not a proper
replacement for strncpy() in this use case.
From Documentation/process/deprecated:
If a caller is using non-NUL-terminated strings, strncpy() can
still be used, but destinations should be marked with the `__nonstring
<https://gcc.gnu.org/onlinedocs/gcc/Common-Variable-Attributes.html>`_
attribute to avoid future compiler warnings.
s_{first,last}_error_func is properly annotated with __nonstring in
fs/ext4/ext4.h.
- Ted
next prev parent reply other threads:[~2020-12-16 4:21 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-11-12 9:33 [PATCH] ext4: fix -Wstringop-truncation warnings Kang Wenlin
2020-12-16 4:20 ` Theodore Y. Ts'o [this message]
2020-12-17 7:00 ` Wenlin Kang
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=X9mLAlWbjrU5iE+r@mit.edu \
--to=tytso@mit.edu \
--cc=adilger.kernel@dilger.ca \
--cc=linux-ext4@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=wenlin.kang@windriver.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).