• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 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 #include "onremotedied_fuzzer.h"
16 #include "if_system_ability_manager.h"
17 #include "init_param.h"
18 #include "iservice_registry.h"
19 #include "iwatcher.h"
20 #include "iwatcher_manager.h"
21 #include "message_parcel.h"
22 #include "parameter.h"
23 #include "param_manager.h"
24 #include "param_utils.h"
25 #include "system_ability_definition.h"
26 #include "watcher.h"
27 #include "watcher_manager.h"
28 #include "watcher_manager_proxy.h"
29 #include "service_watcher.h"
30 #define private public
31 #define protected public
32 #include "watcher_manager_kits.h"
33 #undef protected
34 #undef private
35 using namespace OHOS::init_param;
36 
37 namespace OHOS {
FuzzOnRemoteDied(const uint8_t * data,size_t size)38 bool FuzzOnRemoteDied(const uint8_t* data, size_t size)
39     {
40         int value = 0;
41         if (data == nullptr || size < sizeof(int)) {
42             return false;
43         }
44         errno_t err = memcpy_s(&value, sizeof(int), data, sizeof(int));
45         if (err != 0) {
46             return false;
47         }
48         sptr<ISystemAbilityManager> samgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
49         WATCHER_CHECK(samgr != nullptr, return false, "Get samgr failed");
50         sptr<IRemoteObject> object = samgr->GetSystemAbility(PARAM_WATCHER_DISTRIBUTED_SERVICE_ID);
51         WATCHER_CHECK(object != nullptr, return false, "Get watcher manager object from samgr failed");
52         OHOS::init_param::WatcherManagerKits &instance = OHOS::init_param::WatcherManagerKits::GetInstance();
53         instance.GetService();
54         if (instance.GetDeathRecipient() != nullptr) {
55             instance.GetDeathRecipient()->OnRemoteDied(object);
56         }
57         object = samgr->GetSystemAbility(value);
58         WATCHER_CHECK(object != nullptr, return false, "Get watcher manager object from samgr failed");
59         instance.GetService();
60         if (instance.GetDeathRecipient() != nullptr) {
61             instance.GetDeathRecipient()->OnRemoteDied(object);
62         }
63         return true;
64     }
65 }
66 
67 /* Fuzzer entry point */
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)68 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
69 {
70     /* Run your code on data */
71     OHOS::FuzzOnRemoteDied(data, size);
72     return 0;
73 }