From 59ecf4cae883bbba34413c37dfac6ad4dcc4e631 Mon Sep 17 00:00:00 2001 From: Far Date: Fri, 16 Dec 2022 10:53:03 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8Dclose=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=E4=B8=AD=E6=97=A0=E6=B3=95=E6=AD=A3=E5=B8=B8=E5=85=B3?= =?UTF-8?q?=E9=97=AD=E6=96=87=E4=BB=B6=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1. close未考虑保留描述符0、1和2,导致fd合法性判断出现错误,这会导致 上限附近的fd不能被正常的关闭 2. 释放file结构体时未在锁的保护中进行,可能存在问题 fix #I65U8S Signed-off-by: Far Change-Id: Iaa03a70e18fcb352ca3b99232f50b43d8b13ecf0 --- components/fs/vfs/vfs_config.h | 2 +- components/fs/vfs/vfs_fs.c | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/components/fs/vfs/vfs_config.h b/components/fs/vfs/vfs_config.h index 74640798..3fb0f235 100644 --- a/components/fs/vfs/vfs_config.h +++ b/components/fs/vfs/vfs_config.h @@ -59,7 +59,7 @@ #define CONFIG_NFILE_DESCRIPTORS 256 #endif -#define NR_OPEN_DEFAULT CONFIG_NFILE_DESCRIPTORS +#define NR_OPEN_DEFAULT (CONFIG_NFILE_DESCRIPTORS - MIN_START_FD) /* time configure */ diff --git a/components/fs/vfs/vfs_fs.c b/components/fs/vfs/vfs_fs.c index 8a0bbe4c..22a1c5fb 100644 --- a/components/fs/vfs/vfs_fs.c +++ b/components/fs/vfs/vfs_fs.c @@ -288,7 +288,7 @@ static struct File *VfsAttachFile(int fd, UINT32 status) { struct File *file = NULL; - if ((fd < 0) || (fd >= CONFIG_NFILE_DESCRIPTORS)) { + if ((fd < MIN_START_FD) || (fd >= CONFIG_NFILE_DESCRIPTORS)) { VFS_ERRNO_SET(EBADF); return NULL; } @@ -355,10 +355,10 @@ static int VfsClose(int fd) LOSCFG_FS_FREE_HOOK((void *)file->fullPath); } - VfsDetachFile(file); - VfsFilePut(file); + VfsDetachFile(file); + return ret; } @@ -561,7 +561,7 @@ int close(int fd) #endif int ret = (int)LOS_NOK; - if (fd >= 0 && fd < CONFIG_NFILE_DESCRIPTORS) { + if (fd >= MIN_START_FD && fd < CONFIG_NFILE_DESCRIPTORS) { ret = VfsClose(fd); } return MapToPosixRet(ret); @@ -603,7 +603,7 @@ ssize_t read(int fd, void *buff, size_t bytes) #endif ssize_t ret = (ssize_t)LOS_NOK; - if (fd >= 0 && fd < CONFIG_NFILE_DESCRIPTORS) { + if (fd >= MIN_START_FD && fd < CONFIG_NFILE_DESCRIPTORS) { ret = VfsRead(fd, buff, bytes); } @@ -633,7 +633,7 @@ ssize_t write(int fd, const void *buff, size_t bytes) #endif ssize_t ret = (ssize_t)LOS_NOK; - if (fd >= 0 && fd < CONFIG_NFILE_DESCRIPTORS) { + if (fd >= MIN_START_FD && fd < CONFIG_NFILE_DESCRIPTORS) { ret = VfsWrite(fd, buff, bytes); }