From 3457c0b11debb2cf5d4abe325c2510a750654512 Mon Sep 17 00:00:00 2001 From: chenjing Date: Mon, 7 Jun 2021 15:01:42 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20SysOpenat=E8=BF=94=E5=9B=9E=E5=80=BC?= =?UTF-8?q?=E5=BA=94=E8=AF=A5=E4=B8=BA=E8=BF=9B=E7=A8=8Bfd=EF=BC=8C?= =?UTF-8?q?=E8=80=8C=E9=9D=9E=E7=B3=BB=E7=BB=9F=E5=85=A8=E5=B1=80fd?= =?UTF-8?q?=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit close #I3TNAK Signed-off-by: chenjing Change-Id: Ie754259ead7fc8f4c3b0fa36ef31969dd728b235 --- syscall/fs_syscall.c | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/syscall/fs_syscall.c b/syscall/fs_syscall.c index 2df23ff4..f4cade9f 100644 --- a/syscall/fs_syscall.c +++ b/syscall/fs_syscall.c @@ -1557,6 +1557,7 @@ int SysFtruncate64(int fd, off64_t length) int SysOpenat(int dirfd, const char *path, int oflags, ...) { int ret; + int procFd; char *pathRet = NULL; mode_t mode; #ifdef LOSCFG_FILE_MODE @@ -1572,10 +1573,16 @@ int SysOpenat(int dirfd, const char *path, int oflags, ...) if (path != NULL) { ret = UserPathCopy(path, &pathRet); if (ret != 0) { - goto OUT; + return ret; } } + procFd = AllocProcessFd(); + if (procFd < 0) { + ret = -EMFILE; + goto ERROUT; + } + if (dirfd != AT_FDCWD) { /* Process fd convert to system global fd */ dirfd = GetAssociatedSystemFd(dirfd); @@ -1584,12 +1591,22 @@ int SysOpenat(int dirfd, const char *path, int oflags, ...) ret = do_open(dirfd, (path ? pathRet : NULL), oflags, mode); if (ret < 0) { ret = -get_errno(); + goto ERROUT; } -OUT: + AssociateSystemFd(procFd, ret); if (pathRet != NULL) { (void)LOS_MemFree(OS_SYS_MEM_ADDR, pathRet); } + return procFd; + +ERROUT: + if (pathRet != NULL) { + (void)LOS_MemFree(OS_SYS_MEM_ADDR, pathRet); + } + if (procFd >= 0) { + FreeProcessFd(procFd); + } return ret; }