From e28958fe5c78d85f5ca556662316f86a31b90733 Mon Sep 17 00:00:00 2001 From: chao an Date: Tue, 21 Feb 2023 00:13:19 +0800 Subject: [PATCH] fs/mount: fix compiler warning found out by GCC-12.2 mount/fs_foreachmountpoint.c: In function 'mountpoint_filter': mount/fs_foreachmountpoint.c:99:38: warning: 'sprintf' may write a terminating nul past the end of the destination [-Wformat-overflow=] 99 | sprintf(&dirpath[pathlen], "/%s", node->i_name); | ^ In function 'mountpoint_filter', inlined from 'mountpoint_filter' at mount/fs_foreachmountpoint.c:64:12: mount/fs_foreachmountpoint.c:99:7: note: 'sprintf' output between 2 and 257 bytes into a destination of size 256 99 | sprintf(&dirpath[pathlen], "/%s", node->i_name); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Signed-off-by: chao an --- fs/mount/fs_foreachmountpoint.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fs/mount/fs_foreachmountpoint.c b/fs/mount/fs_foreachmountpoint.c index 81368dd6728..5880407cf68 100644 --- a/fs/mount/fs_foreachmountpoint.c +++ b/fs/mount/fs_foreachmountpoint.c @@ -84,8 +84,8 @@ static int mountpoint_filter(FAR struct inode *node, * name and the path to the directory containing the inode. */ - pathlen = strlen(dirpath); - namlen = strlen(node->i_name) + 1; + pathlen = strnlen(dirpath, PATH_MAX); + namlen = strnlen(node->i_name, PATH_MAX) + 1; /* Make sure that this would not exceed the maximum path length */