linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Xiongfeng Wang <wangxiongfeng2@huawei.com>
To: <dsterba@suse.com>, <clm@fb.com>, <jbacik@fb.com>
Cc: <linux-btrfs@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
	<arnd@arndb.de>, <wangxiongfeng2@huawei.com>
Subject: [PATCH] btrfs: use correct string length
Date: Mon, 8 Jan 2018 19:51:22 +0800	[thread overview]
Message-ID: <1515412282-57381-1-git-send-email-wangxiongfeng2@huawei.com> (raw)

From: Xiongfeng Wang <xiongfeng.wang@linaro.org>

gcc-8 reports

fs/btrfs/ioctl.c: In function 'btrfs_ioctl':
./include/linux/string.h:245:9: warning: '__builtin_strncpy' specified
bound 1024 equals destination size [-Wstringop-truncation]

We need one less byte or call strlcpy() to make it a nul-terminated
string.

Signed-off-by: Xiongfeng Wang <xiongfeng.wang@linaro.org>
---
 fs/btrfs/ioctl.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
index 2ef8aca..e88c9e8 100644
--- a/fs/btrfs/ioctl.c
+++ b/fs/btrfs/ioctl.c
@@ -2807,7 +2807,7 @@ static long btrfs_ioctl_dev_info(struct btrfs_fs_info *fs_info,
 
 		rcu_read_lock();
 		name = rcu_dereference(dev->name);
-		strncpy(di_args->path, name->str, sizeof(di_args->path));
+		strncpy(di_args->path, name->str, sizeof(di_args->path) - 1);
 		rcu_read_unlock();
 		di_args->path[sizeof(di_args->path) - 1] = 0;
 	} else {
-- 
1.8.3.1


             reply	other threads:[~2018-01-08 11:46 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-01-08 11:51 Xiongfeng Wang [this message]
2018-01-09 17:36 ` [PATCH] btrfs: use correct string length David Sterba

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=1515412282-57381-1-git-send-email-wangxiongfeng2@huawei.com \
    --to=wangxiongfeng2@huawei.com \
    --cc=arnd@arndb.de \
    --cc=clm@fb.com \
    --cc=dsterba@suse.com \
    --cc=jbacik@fb.com \
    --cc=linux-btrfs@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    /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).