• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include <gtest/gtest.h>
17 #define private public
18 #include "event_handler.h"
19 #include "event_runner.h"
20 #include "sec_comp_manager.h"
21 #undef private
22 
23 using namespace testing::ext;
24 
25 namespace OHOS {
26 namespace Security {
27 namespace SecurityComponent {
28 /**
29  * @brief This test class is used to release resources before process end to avoid crash
30  */
31 class ZZEnvExitOperate : public testing::Test {
32 public:
33     static void SetUpTestCase();
34     static void TearDownTestCase();
35     void SetUp();
36     void TearDown();
37 };
38 
SetUpTestCase()39 void ZZEnvExitOperate::SetUpTestCase()
40 {}
41 
TearDownTestCase()42 void ZZEnvExitOperate::TearDownTestCase()
43 {}
44 
SetUp()45 void ZZEnvExitOperate::SetUp()
46 {}
47 
TearDown()48 void ZZEnvExitOperate::TearDown()
49 {}
50 
51 /**
52  * @tc.name: ZExitOperateTest001
53  * @tc.desc: remove ffrt handler to avoid uaf crash
54  * @tc.type: FUNC
55  * @tc.require: None
56  */
57 HWTEST_F(ZZEnvExitOperate, ZExitOperateTest001, TestSize.Level1)
58 {
59     if (SecCompManager::GetInstance().secRunner_ != nullptr) {
60         SecCompManager::GetInstance().secRunner_->queue_.reset();
61         SecCompManager::GetInstance().secRunner_ = nullptr;
62     }
63     if (SecCompManager::GetInstance().secHandler_ != nullptr) {
64         SecCompManager::GetInstance().secHandler_->eventRunner_.reset();
65         SecCompManager::GetInstance().secHandler_ = nullptr;
66     }
67     sleep(5);
68 }
69 }
70 }
71 }