From 7c6c826102d978115300d76c239f08041b626f1b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E6=B0=B8=E5=BF=A0?= Date: Fri, 1 Dec 2023 10:01:37 +0000 Subject: [PATCH 1/2] add tdd cfi check MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 王永忠 --- test/unittest/datatransmitmgr/BUILD.gn | 12 ++++ .../unittest/datatransmitmgr/DevSLMgrTest.cpp | 66 +++++++++++++------ 2 files changed, 57 insertions(+), 21 deletions(-) diff --git a/test/unittest/datatransmitmgr/BUILD.gn b/test/unittest/datatransmitmgr/BUILD.gn index e05d367..96cb2b0 100644 --- a/test/unittest/datatransmitmgr/BUILD.gn +++ b/test/unittest/datatransmitmgr/BUILD.gn @@ -33,6 +33,18 @@ ohos_unittest("DevSLMgrTest") { sources = [ "DevSLMgrTest.cpp" ] + if (os_level == "standard") { + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + integer_overflow = true + ubsan = true + boundary_sanitize = true + stack_protector_ret = true + } + } + deps = [ "//base/security/access_token/interfaces/innerkits/accesstoken:libaccesstoken_sdk", "//base/security/access_token/interfaces/innerkits/nativetoken:libnativetoken", diff --git a/test/unittest/datatransmitmgr/DevSLMgrTest.cpp b/test/unittest/datatransmitmgr/DevSLMgrTest.cpp index 4239512..4b81f9e 100644 --- a/test/unittest/datatransmitmgr/DevSLMgrTest.cpp +++ b/test/unittest/datatransmitmgr/DevSLMgrTest.cpp @@ -13,33 +13,22 @@ * limitations under the License. */ +#include "DevSLMgrTest.h" + +#include #include #include #include -#include -#include "gtest/gtest.h" + +#include "accesstoken_kit.h" #include "file_ex.h" +#include "nativetoken_kit.h" #include "securec.h" #include "softbus_bus_center.h" -#include "dev_slinfo_adpt.h" -#include "DevSLMgrTest.h" -#include "DevslinfoListTest.h" -#include "nativetoken_kit.h" #include "token_setproc.h" -#include "accesstoken_kit.h" -using namespace testing::ext; -class DevSLMgrTest : public testing::Test { -public: - DevSLMgrTest(); - ~DevSLMgrTest(); - static void SetUpTestCase(); - static void TearDownTestCase(); - void SetUp() override; - void TearDown() override; -private: - static bool isEnforcing_; -}; +#include "DevslinfoListTest.h" +#include "dev_slinfo_adpt.h" static const int32_t DEV_SEC_LEVEL_ERR = 100; static const int32_t LIST_LENGTH = 128; @@ -53,7 +42,9 @@ struct DeviceSecurityInfo { extern "C" { extern void OnApiDeviceSecInfoCallback(const DeviceIdentify *identify, struct DeviceSecurityInfo *info); } - +namespace OHOS { +namespace Security { +namespace DevSLMgrTest { static void NativeTokenGet() { uint64_t tokenId; @@ -253,6 +244,36 @@ static HWTEST_F(DevSLMgrTest, TestGetHighestSecLevelAsync003, TestSize.Level1) DATASL_OnStop(); } +static int32_t g_cnt = 0; +static std::mutex g_mtx; +static std::condition_variable g_cv; + +static void tmpCallbackLocal(DEVSLQueryParams *queryParams, int32_t result, uint32_t levelInfo) +{ + g_cnt++; + EXPECT_EQ(DEVSL_SUCCESS, result); +} + +static HWTEST_F(DevSLMgrTest, TestGetHighestSecLevelAsync004, TestSize.Level1) +{ + int32_t ret; + DEVSLQueryParams queryParams; + (void)memset_s(&queryParams, sizeof(queryParams), 0, sizeof(queryParams)); + ret = GetLocalUdid(&queryParams); + EXPECT_EQ(DEVSL_SUCCESS, ret); + + ret = DATASL_OnStart(); + EXPECT_EQ(DEVSL_SUCCESS, ret); + ret = DATASL_GetHighestSecLevelAsync(&queryParams, &tmpCallbackLocal); + EXPECT_EQ(DEVSL_SUCCESS, ret); + + std::unique_lock lck(g_mtx); + g_cv.wait_for(lck, std::chrono::milliseconds(2000), []() { return (g_cnt == 1); }); + EXPECT_EQ(g_cnt, 1); + + DATASL_OnStop(); +} + static HWTEST_F(DevSLMgrTest, TestGetHighestSecLevelExcept001, TestSize.Level1) { OnApiDeviceSecInfoCallback(nullptr, nullptr); @@ -447,4 +468,7 @@ static HWTEST_F(DevSLMgrTest, TestGetHighestSecLevelExcept005, TestSize.Level1) ClearList(g_tmpList); g_tmpList = nullptr; DATASL_OnStop(); -} \ No newline at end of file +} +} // namespace DevSLMgrTest +} // namespace Security +} // namespace OHOS \ No newline at end of file -- Gitee From fbcdbd59321ddcaf767548a0b4d139d175fab0fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E6=B0=B8=E5=BF=A0?= Date: Fri, 1 Dec 2023 10:12:15 +0000 Subject: [PATCH 2/2] add tdd cfi check MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 王永忠 --- .../unittest/datatransmitmgr/DevSLMgrTest.cpp | 36 +++++++++++-------- 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/test/unittest/datatransmitmgr/DevSLMgrTest.cpp b/test/unittest/datatransmitmgr/DevSLMgrTest.cpp index 4b81f9e..2e5fd64 100644 --- a/test/unittest/datatransmitmgr/DevSLMgrTest.cpp +++ b/test/unittest/datatransmitmgr/DevSLMgrTest.cpp @@ -13,22 +13,33 @@ * limitations under the License. */ -#include "DevSLMgrTest.h" - -#include #include #include #include - -#include "accesstoken_kit.h" +#include +#include "gtest/gtest.h" #include "file_ex.h" -#include "nativetoken_kit.h" #include "securec.h" #include "softbus_bus_center.h" +#include "dev_slinfo_adpt.h" +#include "DevSLMgrTest.h" +#include "DevslinfoListTest.h" +#include "nativetoken_kit.h" #include "token_setproc.h" +#include "accesstoken_kit.h" -#include "DevslinfoListTest.h" -#include "dev_slinfo_adpt.h" +using namespace testing::ext; +class DevSLMgrTest : public testing::Test { +public: + DevSLMgrTest(); + ~DevSLMgrTest(); + static void SetUpTestCase(); + static void TearDownTestCase(); + void SetUp() override; + void TearDown() override; +private: + static bool isEnforcing_; +}; static const int32_t DEV_SEC_LEVEL_ERR = 100; static const int32_t LIST_LENGTH = 128; @@ -42,9 +53,7 @@ struct DeviceSecurityInfo { extern "C" { extern void OnApiDeviceSecInfoCallback(const DeviceIdentify *identify, struct DeviceSecurityInfo *info); } -namespace OHOS { -namespace Security { -namespace DevSLMgrTest { + static void NativeTokenGet() { uint64_t tokenId; @@ -468,7 +477,4 @@ static HWTEST_F(DevSLMgrTest, TestGetHighestSecLevelExcept005, TestSize.Level1) ClearList(g_tmpList); g_tmpList = nullptr; DATASL_OnStop(); -} -} // namespace DevSLMgrTest -} // namespace Security -} // namespace OHOS \ No newline at end of file +} \ No newline at end of file -- Gitee