From f8b38186246799f6290450957f063ee8f98806b1 Mon Sep 17 00:00:00 2001 From: nan-xiansen Date: Fri, 30 Jul 2021 17:03:26 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90kernel=5Flite=E3=80=91=E3=80=90master?= =?UTF-8?q?=E3=80=91fix=20security=20alarm?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: nan-xiansen Change-Id: I031ad4adfbe104180b3b2a8f5bee169953310667 --- kernel_lite/io_posix/src/IoTestStdio.cpp | 1 + kernel_lite/mem_posix/src/ActsMemApiTest.cpp | 7 ++++++- kernel_lite/net_posix/src/ActsNetTest.cpp | 6 +++--- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/kernel_lite/io_posix/src/IoTestStdio.cpp b/kernel_lite/io_posix/src/IoTestStdio.cpp index c22a6eb50..b1bfb8916 100755 --- a/kernel_lite/io_posix/src/IoTestStdio.cpp +++ b/kernel_lite/io_posix/src/IoTestStdio.cpp @@ -334,6 +334,7 @@ HWTEST_F(IoTest, testVasprintf, Function | MediumTest | Level1) ret = FormatVasprintf(&buf, "%f and %c as well as %ld\n", 2.2, 'c', 6); EXPECT_EQ(ret, 28); EXPECT_STREQ(buf, "2.200000 and c as well as 6\n"); + free(buf); } /** diff --git a/kernel_lite/mem_posix/src/ActsMemApiTest.cpp b/kernel_lite/mem_posix/src/ActsMemApiTest.cpp index 122c6b855..8e2b0c094 100755 --- a/kernel_lite/mem_posix/src/ActsMemApiTest.cpp +++ b/kernel_lite/mem_posix/src/ActsMemApiTest.cpp @@ -297,8 +297,10 @@ HWTEST_F(ActsMemApiTest, testMemmem_0100, Function | MediumTest | Level1) { LogPrint(" memmem *haystack:='%s' size_haystack:='%d' ", srcStr, strlen(srcStr)); LogPrint("*needle:='%s' size_needle:='%d',\n", srcSubStr, strlen(srcSubStr)); + if (strlen(srcStr) >= strlen(srcSubStr)) { pos = (char *)memmem(srcStr, strlen(srcStr), srcSubStr, strlen(srcSubStr)); LogPrint(" --> return pos:='%x'\n", pos); + } ASSERT_TRUE(pos) << "ErrInfo: memmem *haystack:='" << srcStr << " size_haystack:='" @@ -315,7 +317,10 @@ HWTEST_F(ActsMemApiTest, testMemmem_1000, Function | MediumTest | Level1) { char srcStr[] = "this is str a;"; char srcSubStr[] = "strb"; char *pos = nullptr; - + + if (strlen(srcStr) < strlen(srcSubStr)) { + FAIL(); + } pos = (char *)memmem(srcStr, strlen(srcStr), srcSubStr, strlen(srcSubStr)); LogPrint(" memmem *haystack:='%s' size_haystack:='%d' ", srcStr, strlen(srcStr)); LogPrint("*needle:='%s' size_needle:='%d',\n", srcSubStr, strlen(srcSubStr)); diff --git a/kernel_lite/net_posix/src/ActsNetTest.cpp b/kernel_lite/net_posix/src/ActsNetTest.cpp index edbf4fd12..7ed18c837 100755 --- a/kernel_lite/net_posix/src/ActsNetTest.cpp +++ b/kernel_lite/net_posix/src/ActsNetTest.cpp @@ -236,7 +236,7 @@ static void* SampleTcpServerTask(void *p) WAIT(); static char bufrec[BUF_SIZE + 1] = {0}; - memset_s(bufrec, BUF_SIZE, 0, BUF_SIZE); + memset_s(bufrec, sizeof(bufrec), 0, BUF_SIZE); memset_s(&msg, sizeof(msg), 0, sizeof(msg)); msg.msg_name = &clnAddr; msg.msg_namelen = sizeof(clnAddr); @@ -331,7 +331,7 @@ static void* SampleTcpClientTask(void *p) WAIT(); static char bufrec[BUF_SIZE + 1] = {0}; - memset_s(bufrec, BUF_SIZE, 0, BUF_SIZE); + memset_s(bufrec, sizeof(bufrec), 0, BUF_SIZE); memset_s(&msg, sizeof(msg), 0, sizeof(msg)); msg.msg_name = &clnAddr; msg.msg_namelen = sizeof(clnAddr); @@ -340,7 +340,7 @@ static void* SampleTcpClientTask(void *p) iov[0].iov_base = bufrec; iov[0].iov_len = sizeof(bufrec); ret = recvmsg(clnFd, &msg, 0); - if (len * strlen(g_srvMsg) == (unsigned int)ret) { + if (len * strlen(g_srvMsg) == (unsigned int)ret && ret >= 0) { bufrec[ret] = 0; printf("[tcp client]recvmsg, ret=%d, msg[%s]\n", ret, bufrec); } else { -- GitLab