From d84471ff29d0e70902665ae6970424f32f8afe0b Mon Sep 17 00:00:00 2001 From: arvinzzz Date: Wed, 23 Mar 2022 17:15:52 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=91=8A=E8=AD=A6=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: arvinzzz Change-Id: I1c00ca1dda35c62b06bff78353737f7943a647e9 --- components/fs/vfs/vfs_fs.c | 9 +++++++-- kernel/src/los_queue.c | 1 + 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/components/fs/vfs/vfs_fs.c b/components/fs/vfs/vfs_fs.c index ce05503e..b3af9b3f 100644 --- a/components/fs/vfs/vfs_fs.c +++ b/components/fs/vfs/vfs_fs.c @@ -910,12 +910,17 @@ int LOS_Open(const char *path, int flags, ...) { #ifdef LOSCFG_RANDOM_DEV unsigned flagMask = O_RDONLY | O_WRONLY | O_RDWR | O_APPEND | O_CREAT | O_LARGEFILE | O_TRUNC | O_EXCL | O_DIRECTORY; - if (((unsigned)flags & ~flagMask) || (path == NULL)) { + if ((unsigned)flags & ~flagMask) { errno = EINVAL; return LOS_NOK; } size_t pathLen = strlen(path) + 1; + if ((unsigned)pathLen > PATH_MAX) { + errno = EINVAL; + return LOS_NOK; + } + char *canonicalPath = (char *)malloc(pathLen); if (!canonicalPath) { errno = ENOMEM; @@ -952,7 +957,7 @@ int LOS_Open(const char *path, int flags, ...) FREE_AND_SET_NULL(canonicalPath); #endif #if (LOSCFG_POSIX_PIPE_API == 1) - if (!strncmp(path, PIPE_DEV_PATH, strlen(PIPE_DEV_PATH))) { + if ((path != NULL) && !strncmp(path, PIPE_DEV_PATH, strlen(PIPE_DEV_PATH))) { return PipeOpen(path, flags, PIPE_DEV_FD); } #endif diff --git a/kernel/src/los_queue.c b/kernel/src/los_queue.c index 686e5d14..785b2316 100644 --- a/kernel/src/los_queue.c +++ b/kernel/src/los_queue.c @@ -39,6 +39,7 @@ #include "los_memory.h" #include "los_task.h" #include "los_sched.h" +#include #if (LOSCFG_BASE_IPC_QUEUE == 1)