* [PATCH] btrfs: use correct string length
@ 2018-01-08 11:51 Xiongfeng Wang
2018-01-09 17:36 ` David Sterba
0 siblings, 1 reply; 2+ messages in thread
From: Xiongfeng Wang @ 2018-01-08 11:51 UTC (permalink / raw)
To: dsterba, clm, jbacik; +Cc: linux-btrfs, linux-kernel, arnd, wangxiongfeng2
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
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH] btrfs: use correct string length
2018-01-08 11:51 [PATCH] btrfs: use correct string length Xiongfeng Wang
@ 2018-01-09 17:36 ` David Sterba
0 siblings, 0 replies; 2+ messages in thread
From: David Sterba @ 2018-01-09 17:36 UTC (permalink / raw)
To: Xiongfeng Wang; +Cc: dsterba, clm, jbacik, linux-btrfs, linux-kernel, arnd
On Mon, Jan 08, 2018 at 07:51:22PM +0800, Xiongfeng Wang wrote:
> 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.
The null termination is on the following line, so this patch fixes
namely the gcc warning:
> - 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;
Reviewed-by: David Sterba <dsterba@suse.com>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2018-01-09 17:38 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-01-08 11:51 [PATCH] btrfs: use correct string length Xiongfeng Wang
2018-01-09 17:36 ` David Sterba
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).