From d1d9c492f8a2369e1909faf77da1f6b80b7dc1f4 Mon Sep 17 00:00:00 2001 From: Meco Man <920369182@qq.com> Date: Sat, 27 Mar 2021 01:24:32 +0800 Subject: [PATCH] [bug][dfs] rt_strlen(name) + 1) -> DFS_PATH_MAX --- components/dfs/filesystems/elmfat/dfs_elm.c | 2 +- components/dfs/filesystems/nfs/dfs_nfs.c | 2 +- components/dfs/filesystems/romfs/dfs_romfs.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/components/dfs/filesystems/elmfat/dfs_elm.c b/components/dfs/filesystems/elmfat/dfs_elm.c index 07b8f62fed..41f99d7b62 100644 --- a/components/dfs/filesystems/elmfat/dfs_elm.c +++ b/components/dfs/filesystems/elmfat/dfs_elm.c @@ -647,7 +647,7 @@ int dfs_elm_getdents(struct dfs_fd *file, struct dirent *dirp, uint32_t count) d->d_namlen = (rt_uint8_t)rt_strlen(fn); d->d_reclen = (rt_uint16_t)sizeof(struct dirent); - rt_strncpy(d->d_name, fn, rt_strlen(fn) + 1); + rt_strncpy(d->d_name, fn, DFS_PATH_MAX); index ++; if (index * sizeof(struct dirent) >= count) diff --git a/components/dfs/filesystems/nfs/dfs_nfs.c b/components/dfs/filesystems/nfs/dfs_nfs.c index e7ad488f7d..284d8d42af 100644 --- a/components/dfs/filesystems/nfs/dfs_nfs.c +++ b/components/dfs/filesystems/nfs/dfs_nfs.c @@ -1119,7 +1119,7 @@ int nfs_getdents(struct dfs_fd *file, struct dirent *dirp, uint32_t count) d->d_namlen = rt_strlen(name); d->d_reclen = (rt_uint16_t)sizeof(struct dirent); - rt_strncpy(d->d_name, name, rt_strlen(name) + 1); + rt_strncpy(d->d_name, name, DFS_PATH_MAX); index ++; if (index * sizeof(struct dirent) >= count) diff --git a/components/dfs/filesystems/romfs/dfs_romfs.c b/components/dfs/filesystems/romfs/dfs_romfs.c index 1b2693fc3b..2e9b08cbf6 100644 --- a/components/dfs/filesystems/romfs/dfs_romfs.c +++ b/components/dfs/filesystems/romfs/dfs_romfs.c @@ -276,7 +276,7 @@ int dfs_romfs_getdents(struct dfs_fd *file, struct dirent *dirp, uint32_t count) d->d_namlen = rt_strlen(name); d->d_reclen = (rt_uint16_t)sizeof(struct dirent); - rt_strncpy(d->d_name, name, rt_strlen(name) + 1); + rt_strncpy(d->d_name, name, DFS_PATH_MAX); /* move to next position */ ++ file->pos;