From 08ababd7044c5e29ac1a943140ec74c8a2a55f62 Mon Sep 17 00:00:00 2001 From: Xiang Xiao Date: Sun, 5 Mar 2023 21:13:32 +0800 Subject: [PATCH] fs/vfs: Add a new argument(size_t len) to inode_getpath Signed-off-by: Xiang Xiao --- fs/binfs/fs_binfs.c | 5 +++-- fs/inode/fs_inodegetpath.c | 8 ++++---- fs/inode/inode.h | 2 +- fs/romfs/fs_romfs.c | 4 ++-- fs/vfs/fs_dir.c | 2 +- fs/vfs/fs_ioctl.c | 2 +- 6 files changed, 12 insertions(+), 11 deletions(-) diff --git a/fs/binfs/fs_binfs.c b/fs/binfs/fs_binfs.c index 1fe2fa7c8b..92e7dc3bbe 100644 --- a/fs/binfs/fs_binfs.c +++ b/fs/binfs/fs_binfs.c @@ -224,13 +224,14 @@ static int binfs_ioctl(FAR struct file *filep, int cmd, unsigned long arg) } else { - ret = inode_getpath(filep->f_inode, ptr); + ret = inode_getpath(filep->f_inode, ptr, PATH_MAX); if (ret < 0) { return ret; } - strcat(ptr, builtin_getname((int)((uintptr_t)filep->f_priv))); + strlcat(ptr, builtin_getname((int)((uintptr_t)filep->f_priv)), + PATH_MAX); } } else diff --git a/fs/inode/fs_inodegetpath.c b/fs/inode/fs_inodegetpath.c index f3b7b966c1..e0b3572efd 100644 --- a/fs/inode/fs_inodegetpath.c +++ b/fs/inode/fs_inodegetpath.c @@ -42,7 +42,7 @@ * ****************************************************************************/ -int inode_getpath(FAR struct inode *node, FAR char *path) +int inode_getpath(FAR struct inode *node, FAR char *path, size_t len) { if (path == NULL) { @@ -55,17 +55,17 @@ int inode_getpath(FAR struct inode *node, FAR char *path) } else { - int ret = inode_getpath(node->i_parent, path); + int ret = inode_getpath(node->i_parent, path, len); if (ret < 0) { return ret; } } - strcat(path, node->i_name); + strlcat(path, node->i_name, len); if (node->i_child || INODE_IS_MOUNTPT(node)) { - strcat(path, "/"); + strlcat(path, "/", len); } return OK; diff --git a/fs/inode/inode.h b/fs/inode/inode.h index 050b10975f..f5f8727be6 100644 --- a/fs/inode/inode.h +++ b/fs/inode/inode.h @@ -279,7 +279,7 @@ int inode_chstat(FAR struct inode *inode, * ****************************************************************************/ -int inode_getpath(FAR struct inode *node, FAR char *path); +int inode_getpath(FAR struct inode *node, FAR char *path, size_t len); /**************************************************************************** * Name: inode_free diff --git a/fs/romfs/fs_romfs.c b/fs/romfs/fs_romfs.c index ad72d82ea1..eda870dc04 100644 --- a/fs/romfs/fs_romfs.c +++ b/fs/romfs/fs_romfs.c @@ -599,8 +599,8 @@ static int romfs_ioctl(FAR struct file *filep, int cmd, unsigned long arg) if (cmd == FIOC_FILEPATH) { FAR char *ptr = (FAR char *)((uintptr_t)arg); - inode_getpath(filep->f_inode, ptr); - strcat(ptr, rf->rf_path); + inode_getpath(filep->f_inode, ptr, PATH_MAX); + strlcat(ptr, rf->rf_path, PATH_MAX); return OK; } diff --git a/fs/vfs/fs_dir.c b/fs/vfs/fs_dir.c index 8e4d6a6766..eeb8415114 100644 --- a/fs/vfs/fs_dir.c +++ b/fs/vfs/fs_dir.c @@ -599,7 +599,7 @@ int dir_allocate(FAR struct file *filep, FAR const char *relpath) } } - inode_getpath(inode, path_prefix); + inode_getpath(inode, path_prefix, sizeof(path_prefix)); ret = asprintf(&dir->fd_path, "%s%s/", path_prefix, relpath); if (ret < 0) { diff --git a/fs/vfs/fs_ioctl.c b/fs/vfs/fs_ioctl.c index f952733a39..2fcf0e0124 100644 --- a/fs/vfs/fs_ioctl.c +++ b/fs/vfs/fs_ioctl.c @@ -105,7 +105,7 @@ int file_vioctl(FAR struct file *filep, int req, va_list ap) case FIOC_FILEPATH: if (ret == -ENOTTY && !INODE_IS_MOUNTPT(inode)) { - ret = inode_getpath(inode, (FAR char *)(uintptr_t)arg); + ret = inode_getpath(inode, (FAR char *)(uintptr_t)arg, PATH_MAX); } break;