From 3824d1e9e4edc497a25f7e446bd65f254bf54fd9 Mon Sep 17 00:00:00 2001 From: wangchen <253227059@qq.com> Date: Tue, 8 Mar 2022 08:22:45 +0000 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E8=83=8C=E6=99=AF=E3=80=91=E5=86=85?= =?UTF-8?q?=E6=BA=90=E4=BB=A3=E7=A0=81=E6=A3=80=E8=A7=86=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 【修改方案】 1,按检视意见,进行资源泄露等问题的修改 【影响】 对现有的产品编译不会有影响。 re #I4WV56 Signed-off-by: wangchen --- apps/lms/src/sample_usr_lms.c | 3 ++- apps/shell/src/shcmd.c | 2 -- fs/proc/src/proc_file.c | 2 +- fs/vfs/vnode.c | 5 +++++ kernel/base/core/los_process.c | 2 ++ kernel/base/sched/sched_sq/los_sched.c | 6 ++++-- kernel/common/console.c | 4 +++- lib/libscrew/src/los_rbtree.c | 2 +- net/lwip-2.1/enhancement/src/api_shell.c | 2 +- net/lwip-2.1/enhancement/src/fixme.c | 7 +------ .../kernel_base/ipc/event/full/It_los_event_025.c | 2 +- .../unittest/basic/exc/full/it_test_fexecve_001.cpp | 5 +++++ .../unittest/basic/mem/shm/full/shm_test_013.cpp | 3 ++- testsuites/unittest/common/osTest.cpp | 1 + .../unittest/fs/jffs/smoke/it_test_fs_jffs_204.cpp | 2 -- testsuites/unittest/fs/jffs/vfs_jffs_test.cpp | 4 ++-- .../unittest/libc/io/full/It_stdio_hasmntopt_001.cpp | 12 +++++++++--- testsuites/unittest/libc/sys/full/sys_test_026.cpp | 2 +- testsuites/unittest/libc/sys/smoke/sys_test_013.cpp | 5 ++++- .../unittest/libc/time/timer/time_timer_test.cpp | 11 ----------- 20 files changed, 45 insertions(+), 37 deletions(-) diff --git a/apps/lms/src/sample_usr_lms.c b/apps/lms/src/sample_usr_lms.c index 208efb2f..f722db10 100755 --- a/apps/lms/src/sample_usr_lms.c +++ b/apps/lms/src/sample_usr_lms.c @@ -180,7 +180,7 @@ static void LmsFreeTest(void) printf("\n-------- LmsFreeTest Start --------\n"); char *buf = (char *)malloc(16); printf("[LmsFreeTest] malloc addr:%p size:%d\n", buf, 16); - printf("[LmsFreeTest] free addr:%p\n", buf, 16); + printf("[LmsFreeTest] free addr:%p size:%d\n", buf, 16); free(buf); printf("[LmsFreeTest] Use after free error should be triggered, read addr:%p range[1,1]\n", buf); BufReadTest(buf, 1, 1); @@ -204,5 +204,6 @@ int main(int argc, char * const * argv) LmsStrcpyTest(); LmsStrcatTest(); LmsFreeTest(); + free(tmp); printf("\n############### Lms Test End ###############\n"); } \ No newline at end of file diff --git a/apps/shell/src/shcmd.c b/apps/shell/src/shcmd.c index d8563e3a..5142153c 100644 --- a/apps/shell/src/shcmd.c +++ b/apps/shell/src/shcmd.c @@ -36,7 +36,6 @@ #include "dirent.h" #include "securec.h" - #define SHELL_INIT_MAGIC_FLAG 0xABABABAB #define CTRL_C 0x03 /* 0x03: ctrl+c ASCII */ @@ -585,7 +584,6 @@ END: unsigned int OsCmdExec(CmdParsed *cmdParsed, char *cmdStr) { - /* TODO: complete the usrspace command */ unsigned int ret = SH_OK; if (cmdParsed && cmdStr) { ret = SH_NOK; diff --git a/fs/proc/src/proc_file.c b/fs/proc/src/proc_file.c index 9eebcd46..408fc2d9 100644 --- a/fs/proc/src/proc_file.c +++ b/fs/proc/src/proc_file.c @@ -519,7 +519,7 @@ int ProcOpen(struct ProcFile *procFile) static int ProcRead(struct ProcDirEntry *pde, char *buf, size_t len) { - if (pde == NULL || pde == NULL || pde->pf == NULL) { + if (pde == NULL || pde->pf == NULL) { return PROC_ERROR; } struct ProcFile *procFile = pde->pf; diff --git a/fs/vfs/vnode.c b/fs/vfs/vnode.c index c85665ac..494ab091 100644 --- a/fs/vfs/vnode.c +++ b/fs/vfs/vnode.c @@ -380,6 +380,11 @@ int VnodeLookupAt(const char *path, struct Vnode **result, uint32_t flags, struc if (orgVnode != NULL) { startVnode = orgVnode; normalizedPath = strdup(path); + if (normalizedPath == NULL) { + PRINT_ERR("[VFS]lookup failed, strdup err\n"); + ret = -EINVAL; + goto OUT_FREE_PATH; + } } else { ret = PreProcess(path, &startVnode, &normalizedPath); if (ret != LOS_OK) { diff --git a/kernel/base/core/los_process.c b/kernel/base/core/los_process.c index ddfd9fe4..161a3d16 100644 --- a/kernel/base/core/los_process.c +++ b/kernel/base/core/los_process.c @@ -2002,6 +2002,8 @@ LITE_OS_SEC_TEXT VOID LOS_Exit(INT32 status) { UINT32 intSave; + (void)status; + /* The exit of a kernel - state process must be kernel - state and all threads must actively exit */ LosProcessCB *processCB = OsCurrProcessGet(); SCHEDULER_LOCK(intSave); diff --git a/kernel/base/sched/sched_sq/los_sched.c b/kernel/base/sched/sched_sq/los_sched.c index c0a47100..622c8fe6 100644 --- a/kernel/base/sched/sched_sq/los_sched.c +++ b/kernel/base/sched/sched_sq/los_sched.c @@ -578,7 +578,7 @@ BOOL OsSchedModifyTaskSchedParam(LosTaskCB *taskCB, UINT16 policy, UINT16 priori } taskCB->priority = priority; - OsHookCall(LOS_HOOK_TYPE_TASK_PRIMODIFY, taskCB, taskCB->priority); + OsHookCall(LOS_HOOK_TYPE_TASK_PRIMODIFY, taskCB, taskCB->priority); if (taskCB->taskStatus & OS_TASK_STATUS_INIT) { OsSchedTaskEnQueue(taskCB); return TRUE; @@ -771,7 +771,9 @@ BOOL OsSchedSwtmrTimeListFind(SCHED_TL_FIND_FUNC checkFunc, UINTPTR arg) for (UINT16 cpuid = 0; cpuid < LOSCFG_KERNEL_CORE_NUM; cpuid++) { SchedRunQue *rq = OsSchedRunQueByID(cpuid); SortLinkAttribute *swtmrSortLink = &rq->swtmrSortLink; - return SchedSwtmrRunQueFind(swtmrSortLink, checkFunc, arg); + if (SchedSwtmrRunQueFind(swtmrSortLink, checkFunc, arg)) { + return TRUE; + } } return FALSE; } diff --git a/kernel/common/console.c b/kernel/common/console.c index 78d07581..4f072897 100644 --- a/kernel/common/console.c +++ b/kernel/common/console.c @@ -1325,7 +1325,9 @@ INT32 system_console_init(const CHAR *deviceName) LOS_SpinLockSave(&g_consoleSpin, &intSave); (VOID)OsConsoleDelete(consoleCB); g_console[consoleID - 1] = NULL; - g_taskConsoleIDArray[OsCurrTaskGet()->taskID] = 0; + if (OsCurrTaskGet() != NULL) { + g_taskConsoleIDArray[OsCurrTaskGet()->taskID] = 0; + } LOS_SpinUnlockRestore(&g_consoleSpin, intSave); return VFS_ERROR; } diff --git a/lib/libscrew/src/los_rbtree.c b/lib/libscrew/src/los_rbtree.c index 6c2a6702..c9e9b43c 100644 --- a/lib/libscrew/src/los_rbtree.c +++ b/lib/libscrew/src/los_rbtree.c @@ -52,7 +52,7 @@ STATIC VOID OsRbLeftRotateNode(LosRbTree *pstTree, LosRbNode *pstX) LosRbNode *pstNilT = NULL; LosRbNode *pstParent = NULL; - if (NULL == pstTree || NULL == pstX) { + if (pstTree == NULL || pstX == NULL) { return; } pstNilT = &(pstTree->stNilT); diff --git a/net/lwip-2.1/enhancement/src/api_shell.c b/net/lwip-2.1/enhancement/src/api_shell.c index 01f95661..51426bb6 100644 --- a/net/lwip-2.1/enhancement/src/api_shell.c +++ b/net/lwip-2.1/enhancement/src/api_shell.c @@ -3015,7 +3015,7 @@ int netstat_netconn_sendq(struct netconn *conn) retVal = netstat_tcp_sendq(conn->pcb.tcp); break; case NETCONN_RAW: - retVal = 0; /* todo */ + retVal = 0; break; #if PF_PKT_SUPPORT case NETCONN_PKT_RAW: diff --git a/net/lwip-2.1/enhancement/src/fixme.c b/net/lwip-2.1/enhancement/src/fixme.c index 5bb6c3f7..859251c4 100644 --- a/net/lwip-2.1/enhancement/src/fixme.c +++ b/net/lwip-2.1/enhancement/src/fixme.c @@ -144,7 +144,7 @@ err_t netifapi_dhcps_stop(struct netif *netif) */ static void tcp_unlock_accept(ip6_addr_t *ipaddr) { - // FIXME + } static void netif_ip6_addr_setinvalid(struct netif *netif, const ip6_addr_t *addr6) @@ -327,26 +327,22 @@ err_t netif_set_hwaddr(struct netif *netif, const unsigned char *hw_addr, int hw err_t etharp_update_arp_entry(struct netif *netif, const ip4_addr_t *ipaddr, struct eth_addr *ethaddr, u8_t flags) { - // FIXME return 0; } err_t etharp_delete_arp_entry(struct netif *netif, ip4_addr_t *ipaddr) { - // FIXME return 0; } err_t lwip_dns_setserver(u8_t numdns, ip_addr_t *dnsserver) { - // FIXME return 0; } err_t lwip_dns_getserver(u8_t numdns, ip_addr_t *dnsserver) { - // FIXME return 0; } @@ -372,7 +368,6 @@ sys_sem_t dup_addr_detect; int lwip_sntp_start(int server_num, char **sntp_server, struct timeval *time) { - // FIXME return 0; } diff --git a/testsuites/kernel/sample/kernel_base/ipc/event/full/It_los_event_025.c b/testsuites/kernel/sample/kernel_base/ipc/event/full/It_los_event_025.c index e582f5df..51a81143 100644 --- a/testsuites/kernel/sample/kernel_base/ipc/event/full/It_los_event_025.c +++ b/testsuites/kernel/sample/kernel_base/ipc/event/full/It_los_event_025.c @@ -69,7 +69,7 @@ static UINT32 Testcase(VOID) tickNum = (osEndTime - osStartTime) * LOSCFG_BASE_CORE_TICK_PER_SECOND / OS_SYS_CLOCK; - if (tickNum < (10 - 2) && tickNum > (10 + 2)) { // when tick num in 10 - 2 or 10 + 2 interval + if (tickNum < (10 - 2) || tickNum > (10 + 2)) { // when tick num in 10 - 2 or 10 + 2 interval ICUNIT_ASSERT_EQUAL(tickNum, 0, tickNum); } ret = LOS_EventClear(&g_event, 0); diff --git a/testsuites/unittest/basic/exc/full/it_test_fexecve_001.cpp b/testsuites/unittest/basic/exc/full/it_test_fexecve_001.cpp index e4cfa5eb..7aeb897a 100644 --- a/testsuites/unittest/basic/exc/full/it_test_fexecve_001.cpp +++ b/testsuites/unittest/basic/exc/full/it_test_fexecve_001.cpp @@ -82,16 +82,21 @@ static int TestCase(void) printf("fd=%d\n", fd); if (fd == -1) { perror("openls"); + munmap(p, st.st_size); return -1; } rc = read(fd, p, st.st_size); if (rc == -1) { perror("read"); + munmap(p, st.st_size); + close(shmFd); return -1; } if (rc != st.st_size) { fputs("Strange situation!\n", stderr); + munmap(p, st.st_size); + close(shmFd); return -1; } diff --git a/testsuites/unittest/basic/mem/shm/full/shm_test_013.cpp b/testsuites/unittest/basic/mem/shm/full/shm_test_013.cpp index 72375cfe..19fb4fc6 100644 --- a/testsuites/unittest/basic/mem/shm/full/shm_test_013.cpp +++ b/testsuites/unittest/basic/mem/shm/full/shm_test_013.cpp @@ -44,9 +44,10 @@ static int testcase(void) ICUNIT_ASSERT_NOT_EQUAL(shmfd, -1, shmfd); writebuf = (char*)malloc(pageSize); + ICUNIT_ASSERT_NOT_EQUAL(writebuf, NULL, writebuf); readbuf = (char*)malloc(pageSize); ICUNIT_ASSERT_NOT_EQUAL(readbuf, NULL, readbuf); - ICUNIT_ASSERT_NOT_EQUAL(writebuf, NULL, writebuf); + memset_s(writebuf, pageSize, 0xf, pageSize); count = write(shmfd, writebuf, pageSize); diff --git a/testsuites/unittest/common/osTest.cpp b/testsuites/unittest/common/osTest.cpp index 3b0ca940..f1e70b69 100644 --- a/testsuites/unittest/common/osTest.cpp +++ b/testsuites/unittest/common/osTest.cpp @@ -460,6 +460,7 @@ int RemoveDir(const char *dir) ret = sprintf_s(dir_name, sizeof(dir_name), "%s/%s", dir, dp->d_name); if (ret < 0) { perror("sprintf dir_name error"); + closedir(dirp); return -1; } RemoveDir(dir_name); diff --git a/testsuites/unittest/fs/jffs/smoke/it_test_fs_jffs_204.cpp b/testsuites/unittest/fs/jffs/smoke/it_test_fs_jffs_204.cpp index 1206baff..264dec4e 100644 --- a/testsuites/unittest/fs/jffs/smoke/it_test_fs_jffs_204.cpp +++ b/testsuites/unittest/fs/jffs/smoke/it_test_fs_jffs_204.cpp @@ -55,8 +55,6 @@ static int TestCase(void) ret = unlinkat(dirFd, FILEPATH, AT_REMOVEDIR); ICUNIT_GOTO_NOT_EQUAL(ret, JFFS_IS_ERROR, ret, EXIT1); - return JFFS_NO_ERROR; - EXIT1: close(fd); unlink(DIRPATH); diff --git a/testsuites/unittest/fs/jffs/vfs_jffs_test.cpp b/testsuites/unittest/fs/jffs/vfs_jffs_test.cpp index 4bd98f91..f71c5f49 100644 --- a/testsuites/unittest/fs/jffs/vfs_jffs_test.cpp +++ b/testsuites/unittest/fs/jffs/vfs_jffs_test.cpp @@ -353,7 +353,7 @@ INT32 JffsFixWrite(CHAR *path, INT64 fileSize, INT32 writeSize, INT32 interfaceT gettimeofday(&testTime2, 0); perTime = (testTime2.tv_sec - testTime1.tv_sec) * USECS_PER_SEC + (testTime2.tv_usec - testTime1.tv_usec); - printf("fix_Write TaskID:%3d,sucess to fclose the %s ,task:%d ms,\n", taskId, path, MSECS_PER_SEC / MSECS_PER_SEC); + printf("fix_Write TaskID:%3d,sucess to fclose the %s ,task:%d ms,\n", taskId, path, (perTime / USECS_PER_SEC) * MSECS_PER_SEC); free(writeBuf); @@ -1000,7 +1000,7 @@ public: }; #if defined(LOSCFG_USER_TEST_FULL) /* * - * @tc.name: IO_TEST_FACCESSAT_001 + * @tc.name: IO_TEST_FACCESSAT_001 * @tc.desc: normal tests for faccessat * @tc.type: FUNC * @tc.require: AR000EEMQ9 diff --git a/testsuites/unittest/libc/io/full/It_stdio_hasmntopt_001.cpp b/testsuites/unittest/libc/io/full/It_stdio_hasmntopt_001.cpp index 2169f01c..f493a15c 100644 --- a/testsuites/unittest/libc/io/full/It_stdio_hasmntopt_001.cpp +++ b/testsuites/unittest/libc/io/full/It_stdio_hasmntopt_001.cpp @@ -35,6 +35,7 @@ static UINT32 testcase(VOID) struct mntent* mnt = nullptr; struct mntent* mnt_new = nullptr; FILE *fp = nullptr; + FILE *fp2 = nullptr; char *argv[2] = {nullptr}; argv[0] = "/etc/fstab"; argv[1] = "errors"; @@ -45,14 +46,14 @@ static UINT32 testcase(VOID) char *pathList[] = {"/etc/fstab"}; char *streamList[] = {(char *)fileWords}; int streamLen[] = {sizeof(fileWords)}; - + int flag = PrepareFileEnv(pathList, streamList, streamLen, 1); if (flag != 0) { printf("error: need some env file, but prepare is not ok"); (VOID)RecoveryFileEnv(pathList, 1); return -1; } - + mnt_new = (struct mntent *)malloc(sizeof(struct mntent)); mnt_new->mnt_fsname = "UUID=c4992556-a86e-45e8-ba5f-190b16a9073x"; mnt_new->mnt_dir = "/usr1"; @@ -64,6 +65,7 @@ static UINT32 testcase(VOID) fp = setmntent("/etc/fstab", "r"); if (!fp) { printf("fp=0x%x\n", fp); + free(mnt_new); return LOS_NOK; } @@ -81,7 +83,8 @@ static UINT32 testcase(VOID) /* test the addmntent below */ fp = setmntent(argv[0], "a"); - if (fopen("/lib/libc.so", "r")) { + fp2 = fopen("/lib/libc.so", "r"); + if (fp2 != NULL) { printf("aha I found you are OHOS!!!\n"); if (addmntent(fp, mnt_new)) { printf("a new mnt is added to %s\n", argv[0]); @@ -91,6 +94,9 @@ static UINT32 testcase(VOID) if (fp != NULL) { endmntent(fp); } + if (fp2 != NULL) { + fclose(fp2); + } (VOID)RecoveryFileEnv(pathList, 1); return LOS_OK; } diff --git a/testsuites/unittest/libc/sys/full/sys_test_026.cpp b/testsuites/unittest/libc/sys/full/sys_test_026.cpp index 80b9244b..106bce0c 100644 --- a/testsuites/unittest/libc/sys/full/sys_test_026.cpp +++ b/testsuites/unittest/libc/sys/full/sys_test_026.cpp @@ -34,7 +34,7 @@ static int TestCase(void) { char *name = getlogin(); ICUNIT_ASSERT_NOT_EQUAL(name, "USER1", NULL); - int ret = getlogin_r(name, sizeof(name)); + int ret = getlogin_r(name, strlen(name) + 1); ICUNIT_ASSERT_EQUAL(ret, 6, ret); ret = setenv("LOGNAME", "USER1", 1); ICUNIT_ASSERT_EQUAL(ret, 0, ret); diff --git a/testsuites/unittest/libc/sys/smoke/sys_test_013.cpp b/testsuites/unittest/libc/sys/smoke/sys_test_013.cpp index 43402cab..97f9b074 100644 --- a/testsuites/unittest/libc/sys/smoke/sys_test_013.cpp +++ b/testsuites/unittest/libc/sys/smoke/sys_test_013.cpp @@ -39,7 +39,10 @@ struct q { static struct q *New(int i) { struct q *q = (struct q *)malloc(sizeof *q); - q->i = i; + if (q != NULL) { + q->i = i; + } + return q; } diff --git a/testsuites/unittest/libc/time/timer/time_timer_test.cpp b/testsuites/unittest/libc/time/timer/time_timer_test.cpp index dc2d9648..dae658f5 100644 --- a/testsuites/unittest/libc/time/timer/time_timer_test.cpp +++ b/testsuites/unittest/libc/time/timer/time_timer_test.cpp @@ -76,17 +76,6 @@ HWTEST_F(TimeTimerTest, TimerTest003, TestSize.Level0) TimerTest003(); } -/* * - * @tc.name: TimerTest004 - * @tc.desc: function for TimeTimerTest - * @tc.type: FUNC - * @tc.require: AR000EEMQ9 - */ -/*HWTEST_F(TimeTimerTest, TimerTest004, TestSize.Level0) -{ - TimerTest004(); // TODO: musl sigaction handler have only one param. -}*/ - /* * * @tc.name: TimerTest005 * @tc.desc: function for timer_create SIGEV_THREAD.