diff --git a/fs/proc/os_adapt/process_proc.c b/fs/proc/os_adapt/process_proc.c index 39764dc0f0dd17a6ce6ea7b8f855d7d110166d3c..f9a9d53acb98562ec8316a9e32622534c986b016 100644 --- a/fs/proc/os_adapt/process_proc.c +++ b/fs/proc/os_adapt/process_proc.c @@ -103,6 +103,8 @@ static ssize_t ProcessContainerLink(unsigned int containerID, ContainerType type static ssize_t ProcessContainerReadLink(struct ProcDirEntry *entry, char *buffer, size_t bufLen) { + char *freeBuf = NULL; + char *buf = buffer; ssize_t count; unsigned int intSave; if (entry == NULL) { @@ -112,17 +114,41 @@ static ssize_t ProcessContainerReadLink(struct ProcDirEntry *entry, char *buffer if (data == NULL) { return -EINVAL; } + + if (LOS_IsUserAddressRange((VADDR_T)(UINTPTR)buffer, bufLen)) { + buf = LOS_MemAlloc(m_aucSysMem1, bufLen); + if (buf == NULL) { + return -ENOMEM; + } + (void)memset_s(buf, bufLen, 0, bufLen); + freeBuf = buf; + } + LosProcessCB *processCB = ProcGetProcessCB(data); SCHEDULER_LOCK(intSave); UINT32 containerID = OsGetContainerID(processCB, (ContainerType)data->type); SCHEDULER_UNLOCK(intSave); if (containerID != OS_INVALID_VALUE) { - return ProcessContainerLink(containerID, (ContainerType)data->type, buffer, bufLen); + count = ProcessContainerLink(containerID, (ContainerType)data->type, buf, bufLen); + } else { + count = strlen("(unknown)"); + if (memcpy_s(buf, bufLen, "(unknown)", count + 1) != EOK) { + (void)LOS_MemFree(m_aucSysMem1, freeBuf); + return -EBADF; + } } - count = strlen("(unknown)"); - if (memcpy_s(buffer, bufLen, "(unknown)", count + 1) != EOK) { - return -EBADF; + if (count < 0) { + (void)LOS_MemFree(m_aucSysMem1, freeBuf); + return count; + } + + if (LOS_IsUserAddressRange((VADDR_T)(UINTPTR)buffer, bufLen)) { + if (LOS_ArchCopyToUser(buffer, buf, bufLen) != 0) { + (void)LOS_MemFree(m_aucSysMem1, freeBuf); + return -EFAULT; + } } + (void)LOS_MemFree(m_aucSysMem1, freeBuf); return count; } diff --git a/fs/vfs/vnode.c b/fs/vfs/vnode.c index b8b513dcc58ed869ed11ad4e5374163896a90409..4f97adb07d1c4ac1d785c2678d42f6463dfe2d02 100644 --- a/fs/vfs/vnode.c +++ b/fs/vfs/vnode.c @@ -138,7 +138,7 @@ int VnodeAlloc(struct VnodeOps *vop, struct Vnode **newVnode) VnodeHold(); vnode = GetFromFreeList(); if ((vnode == NULL) && g_totalVnodeSize < LOSCFG_MAX_VNODE_SIZE) { - vnode = (struct Vnode*)zalloc(sizeof(struct Vnode)); + vnode = (struct Vnode *)zalloc(sizeof(struct Vnode)); g_totalVnodeSize++; } diff --git a/syscall/fs_syscall.c b/syscall/fs_syscall.c index fefff88d03401bd3914e2b17426c182d21a61ca8..eec9b5b486c0704de3fcdc0f662f5112ec2710ee 100644 --- a/syscall/fs_syscall.c +++ b/syscall/fs_syscall.c @@ -321,7 +321,7 @@ static unsigned int ProcRealProcessIDGet(unsigned int pid) SCHEDULER_LOCK(intSave); LosProcessCB *pcb = OsGetPCBFromVpid(pid); - if (pcb == NULL) { + if (OsProcessIsInactive(pcb)) { SCHEDULER_UNLOCK(intSave); return 0; } diff --git a/testsuites/unittest/process/fs/smoke/It_process_fs_013.cpp b/testsuites/unittest/process/fs/smoke/It_process_fs_013.cpp index b4afdb099ccf330219d78220212aab111092d35d..d34d49d587e1d4c503998b6e3bd1b10fd52ae98a 100644 --- a/testsuites/unittest/process/fs/smoke/It_process_fs_013.cpp +++ b/testsuites/unittest/process/fs/smoke/It_process_fs_013.cpp @@ -30,19 +30,13 @@ #include #include "It_process_fs_test.h" -static const int ini_process_max = 3; - void ItProcessFs013(void) { std::string path; DIR *dirp = nullptr; - for (int i = 1; i <= ini_process_max; i++) { - if (i != 2) { /* 2: skip kernel process */ - path = GenProcPidPath(i); - printf("path: %s\n", path.c_str()); - dirp = opendir(path.data()); - ASSERT_NE(dirp, nullptr); - (void)closedir(dirp); - }; - } + path = GenProcPidPath(1); + printf("path: %s\n", path.c_str()); + dirp = opendir(path.data()); + ASSERT_NE(dirp, nullptr); + (void)closedir(dirp); }