• 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 "distributedschedservicesix_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 
DurationStartFuzzTest(const uint8_t * data,size_t size)41 void DurationStartFuzzTest(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 srcDeviceId = fdp.ConsumeRandomLengthString();
49     std::string dstDeviceId = fdp.ConsumeRandomLengthString();
50     DistributedSchedService::GetInstance().DurationStart(srcDeviceId, dstDeviceId);
51 }
52 
GetCallerInfoFuzzTest(const uint8_t * data,size_t size)53 void GetCallerInfoFuzzTest(const uint8_t* data, size_t size)
54 {
55     if (data == nullptr || size < sizeof(int32_t)) {
56         return;
57     }
58 
59     FuzzedDataProvider fdp(data, size);
60     std::string localDeviceId = fdp.ConsumeRandomLengthString();
61     int32_t callerUid = fdp.ConsumeIntegral<int32_t>();
62     uint32_t accessToken = fdp.ConsumeIntegral<uint32_t>();
63     CallerInfo callerInfo;
64     DistributedSchedService::GetInstance().GetCallerInfo(localDeviceId, callerUid, accessToken, callerInfo);
65 }
66 
StartRemoteAbilityFuzzTest(const uint8_t * data,size_t size)67 void StartRemoteAbilityFuzzTest(const uint8_t* data, size_t size)
68 {
69     if (data == nullptr || size < sizeof(int32_t)) {
70         return;
71     }
72 
73     FuzzedDataProvider fdp(data, size);
74     AAFwk::Want want;
75     int32_t callerUid = fdp.ConsumeIntegral<int32_t>();
76     uint32_t accessToken = fdp.ConsumeIntegral<uint32_t>();
77     int32_t requestCode = fdp.ConsumeIntegral<int32_t>();
78     DistributedSchedService::GetInstance().StartRemoteAbility(want, callerUid, requestCode, accessToken);
79 }
80 
StartAbilityFromRemoteFuzzTest(const uint8_t * data,size_t size)81 void StartAbilityFromRemoteFuzzTest(const uint8_t* data, size_t size)
82 {
83     if (data == nullptr || size < sizeof(int32_t)) {
84         return;
85     }
86 
87     FuzzedDataProvider fdp(data, size);
88     AAFwk::Want want;
89     AppExecFwk::AbilityInfo abilityInfo;
90     CallerInfo callerInfo;
91     callerInfo.sourceDeviceId = fdp.ConsumeRandomLengthString();
92     callerInfo.uid = fdp.ConsumeIntegral<int32_t>();
93     AccountInfo accountInfo;
94     int32_t requestCode = fdp.ConsumeIntegral<int32_t>();
95     DistributedSchedService::GetInstance().StartAbilityFromRemote(
96         want, abilityInfo, requestCode, callerInfo, accountInfo);
97 }
98 
SendResultFromRemoteFuzzTest(const uint8_t * data,size_t size)99 void SendResultFromRemoteFuzzTest(const uint8_t* data, size_t size)
100 {
101     if (data == nullptr || size < sizeof(int32_t)) {
102         return;
103     }
104 
105     FuzzedDataProvider fdp(data, size);
106     AAFwk::Want want;
107     std::string deviceId = fdp.ConsumeRandomLengthString();
108     std::string bundleName = fdp.ConsumeRandomLengthString();
109     std::string abilityName = fdp.ConsumeRandomLengthString();
110     AppExecFwk::ElementName element(deviceId, bundleName, abilityName);
111     want.SetElement(element);
112     want.SetParam("dmsSrcNetworkId", deviceId);
113     want.SetParam("dmsMissionId", fdp.ConsumeIntegral<int32_t>());
114 
115     CallerInfo callerInfo;
116     callerInfo.sourceDeviceId = fdp.ConsumeRandomLengthString();
117     callerInfo.uid = fdp.ConsumeIntegral<int32_t>();
118 
119     AccountInfo accountInfo;
120     int32_t requestCode = fdp.ConsumeIntegral<int32_t>();
121     int32_t resultCode = fdp.ConsumeIntegral<int32_t>();
122     DistributedSchedService::GetInstance().SendResultFromRemote(want, requestCode, callerInfo, accountInfo, resultCode);
123 }
124 }
125 }
126 /* Fuzzer entry point */
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)127 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
128 {
129     OHOS::DistributedSchedule::DurationStartFuzzTest(data, size);
130     OHOS::DistributedSchedule::GetCallerInfoFuzzTest(data, size);
131     OHOS::DistributedSchedule::StartRemoteAbilityFuzzTest(data, size);
132     OHOS::DistributedSchedule::StartAbilityFromRemoteFuzzTest(data, size);
133     OHOS::DistributedSchedule::SendResultFromRemoteFuzzTest(data, size);
134     return 0;
135 }
136