• 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 
16 #include "distributedschedserviceone_fuzzer.h"
17 
18 #include <cstddef>
19 #include <cstdint>
20 #include <fuzzer/FuzzedDataProvider.h>
21 #include <singleton.h>
22 
23 #include "distributed_sched_interface.h"
24 #include "distributed_sched_service.h"
25 #include "distributed_sched_stub.h"
26 #include "distributedWant/distributed_want.h"
27 #include "mock_fuzz_util.h"
28 #include "mock_distributed_sched.h"
29 #include "parcel_helper.h"
30 #include "dms_continue_time_dumper.h"
31 
32 using namespace OHOS::AAFwk;
33 using namespace OHOS::AppExecFwk;
34 
35 namespace OHOS {
36 namespace DistributedSchedule {
37 
38 std::string GetDExtensionName(std::string bundleName, int32_t userId);
39 std::string GetDExtensionProcess(std::string bundleName, int32_t userId);
40 
DeviceOfflineNotifyFuzzTest(const uint8_t * data,size_t size)41 void DeviceOfflineNotifyFuzzTest(const uint8_t* data, size_t size)
42 {
43     if ((data == nullptr) || (size < sizeof(int32_t))) {
44         return;
45     }
46 
47     FuzzedDataProvider fdp(data, size);
48     std::string networkId = fdp.ConsumeRandomLengthString();
49     DistributedSchedService::GetInstance().DeviceOfflineNotify(networkId);
50 }
51 
DeviceOfflineNotifyAfterDeleteFuzzTest(const uint8_t * data,size_t size)52 void DeviceOfflineNotifyAfterDeleteFuzzTest(const uint8_t* data, size_t size)
53 {
54     if ((data == nullptr) || (size < sizeof(int32_t))) {
55         return;
56     }
57 
58     FuzzedDataProvider fdp(data, size);
59     std::string networkId = fdp.ConsumeRandomLengthString();
60     DistributedSchedService::GetInstance().DeviceOfflineNotifyAfterDelete(networkId);
61 }
62 }
63 }
64 /* Fuzzer entry point */
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)65 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
66 {
67     OHOS::DistributedSchedule::DeviceOfflineNotifyFuzzTest(data, size);
68     OHOS::DistributedSchedule::DeviceOfflineNotifyAfterDeleteFuzzTest(data, size);
69     return 0;
70 }
71