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 "distributedschedstub_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 const std::string TAG = "DistributedSchedFuzzTest";
38 namespace {
39 const std::u16string DMS_STUB_INTERFACE_TOKEN = u"ohos.distributedschedule.accessToken";
40 const uint32_t ONE = 1;
41 constexpr size_t FOO_MAX_LEN = 1024;
42 constexpr size_t U32_AT_SIZE = 4;
43 }
44
GetU32Data(const uint8_t * ptr,size_t size)45 uint32_t GetU32Data(const uint8_t* ptr, size_t size)
46 {
47 if (size > FOO_MAX_LEN || size < U32_AT_SIZE) {
48 return 0;
49 }
50 char *ch = static_cast<char *>(malloc(size + 1));
51 if (ch == nullptr) {
52 std::cout << "malloc failed." << std::endl;
53 return 0;
54 }
55 (void)memset_s(ch, size + 1, 0x00, size + 1);
56 if (memcpy_s(ch, size + 1, ptr, size) != EOK) {
57 std::cout << "copy failed." << std::endl;
58 free(ch);
59 ch = nullptr;
60 return 0;
61 }
62 uint32_t data = (ch[0] << 24) | (ch[1] << 16) | (ch[2] << 8) | ch[3];
63 free(ch);
64 ch = nullptr;
65 return data;
66 }
67
StartRemoteAbilityInnerFuzzTest(const uint8_t * data,size_t size)68 bool StartRemoteAbilityInnerFuzzTest(const uint8_t* data, size_t size)
69 {
70 if ((data == nullptr) || (size < sizeof(int32_t))) {
71 return false;
72 }
73 MessageParcel dataParcel;
74 MessageParcel reply;
75 Want want;
76 FuzzedDataProvider fdp(data, size);
77 int32_t int32Data = fdp.ConsumeIntegral<int32_t>();
78 uint32_t uint32Data = fdp.ConsumeIntegral<uint32_t>();
79
80 PARCEL_WRITE_HELPER(dataParcel, Parcelable, &want);
81 PARCEL_WRITE_HELPER(dataParcel, Int32, int32Data);
82 PARCEL_WRITE_HELPER(dataParcel, Int32, int32Data);
83 PARCEL_WRITE_HELPER(dataParcel, Uint32, uint32Data);
84 DistributedSchedService::GetInstance().StartRemoteAbilityInner(dataParcel, reply);
85 FuzzUtil::MockPermission();
86 DistributedSchedService::GetInstance().StartRemoteAbilityInner(dataParcel, reply);
87 return true;
88 }
89
ConnectRemoteAbilityInnerFuzzTest(const uint8_t * data,size_t size)90 void ConnectRemoteAbilityInnerFuzzTest(const uint8_t* data, size_t size)
91 {
92 if ((data == nullptr) || (size < sizeof(int32_t))) {
93 return;
94 }
95 FuzzUtil::MockPermission();
96 MessageParcel dataParcel;
97 MessageParcel reply;
98 MessageOption option;
99 Want want;
100 sptr<IRemoteObject> connect(new MockDistributedSched());
101 FuzzedDataProvider fdp(data, size);
102 int32_t int32Data = fdp.ConsumeIntegral<int32_t>();
103 uint32_t uint32Data = fdp.ConsumeIntegral<uint32_t>();
104
105 PARCEL_WRITE_HELPER_NORET(dataParcel, Parcelable, &want);
106 PARCEL_WRITE_HELPER_NORET(dataParcel, RemoteObject, connect);
107 PARCEL_WRITE_HELPER_NORET(dataParcel, Int32, int32Data);
108 PARCEL_WRITE_HELPER_NORET(dataParcel, Int32, int32Data);
109 PARCEL_WRITE_HELPER_NORET(dataParcel, Uint32, uint32Data);
110 DistributedSchedService::GetInstance().ConnectRemoteAbilityInner(dataParcel, reply);
111 std::string devId(reinterpret_cast<const char*>(data), size);
112 DistributedSchedService::GetInstance().InitDataShareManager();
113 DistributedSchedService::GetInstance().InitCommonEventListener();
114 DistributedSchedService::GetInstance().InitWifiStateListener();
115 DistributedSchedService::GetInstance().GetFormMgrProxy();
116 DistributedSchedService::GetInstance().ProcessFreeInstallOffline(devId);
117 DistributedSchedService::GetInstance().ProcessCalleeOffline(devId);
118 }
119
DisconnectRemoteAbilityInnerFuzzTest(const uint8_t * data,size_t size)120 void DisconnectRemoteAbilityInnerFuzzTest(const uint8_t* data, size_t size)
121 {
122 if ((data == nullptr) || (size < sizeof(int32_t))) {
123 return;
124 }
125 FuzzUtil::MockPermission();
126 MessageParcel dataParcel;
127 MessageParcel reply;
128 MessageOption option;
129 sptr<IRemoteObject> connect(new MockDistributedSched());
130 FuzzedDataProvider fdp(data, size);
131 int32_t int32Data = fdp.ConsumeIntegral<int32_t>();
132 uint32_t uint32Data = fdp.ConsumeIntegral<uint32_t>();
133
134 PARCEL_WRITE_HELPER_NORET(dataParcel, RemoteObject, connect);
135 PARCEL_WRITE_HELPER_NORET(dataParcel, Int32, int32Data);
136 PARCEL_WRITE_HELPER_NORET(dataParcel, Uint32, uint32Data);
137 DistributedSchedService::GetInstance().DisconnectRemoteAbilityInner(dataParcel, reply);
138
139 std::string networkId(reinterpret_cast<const char*>(data), size);
140 std::string bundleName(reinterpret_cast<const char*>(data), size);
141 DistributedSchedService::GetInstance().IsRemoteInstall(networkId, bundleName);
142 DistributedSchedService::GetInstance().GetContinueInfo(networkId, networkId);
143 }
144
StartContinuationInnerFuzzTest(const uint8_t * data,size_t size)145 void StartContinuationInnerFuzzTest(const uint8_t* data, size_t size)
146 {
147 if ((data == nullptr) || (size < sizeof(int32_t))) {
148 return;
149 }
150 FuzzUtil::MockPermission();
151 MessageParcel dataParcel;
152 MessageParcel reply;
153 MessageOption option;
154 Want want;
155 FuzzedDataProvider fdp(data, size);
156 int32_t missionId = fdp.ConsumeIntegral<int32_t>();
157 int32_t callerUid = fdp.ConsumeIntegral<int32_t>();
158 int32_t status = fdp.ConsumeIntegral<int32_t>();
159 uint32_t accessToken = fdp.ConsumeIntegral<uint32_t>();
160
161 dataParcel.WriteParcelable(&want);
162 dataParcel.WriteInt32(missionId);
163 dataParcel.WriteInt32(callerUid);
164 dataParcel.WriteInt32(status);
165 dataParcel.WriteUint32(accessToken);
166 DistributedSchedService::GetInstance().StartContinuationInner(dataParcel, reply);
167 DistributedSchedService::GetInstance().StartAbility(want, callerUid);
168 DistributedSchedService::GetInstance().GetAppManager();
169 }
170
NotifyCompleteContinuationInnerFuzzTest(const uint8_t * data,size_t size)171 void NotifyCompleteContinuationInnerFuzzTest(const uint8_t* data, size_t size)
172 {
173 if ((data == nullptr) || (size < sizeof(int32_t))) {
174 return;
175 }
176 FuzzUtil::MockPermission();
177 FuzzedDataProvider fdp(data, size);
178 bool isSuccess = fdp.ConsumeBool();
179 int32_t sessionId = fdp.ConsumeIntegral<int32_t>();
180 std::string devId = fdp.ConsumeRandomLengthString();
181 MessageParcel dataParcel;
182 MessageParcel reply;
183 MessageOption option;
184
185 dataParcel.WriteString16(Str8ToStr16(devId));
186 dataParcel.WriteInt32(sessionId);
187 dataParcel.WriteBool(isSuccess);
188 DistributedSchedService::GetInstance().NotifyCompleteContinuationInner(dataParcel, reply);
189 }
190
ContinueMissionInnerFuzzTest(const uint8_t * data,size_t size)191 void ContinueMissionInnerFuzzTest(const uint8_t* data, size_t size)
192 {
193 if ((data == nullptr) || (size < sizeof(int32_t))) {
194 return;
195 }
196 FuzzUtil::MockPermission();
197 MessageParcel dataParcel;
198 MessageParcel reply;
199 MessageOption option;
200 FuzzedDataProvider fdp(data, size);
201 int32_t int32Data = fdp.ConsumeIntegral<int32_t>();
202 std::string str = fdp.ConsumeRandomLengthString();
203 std::string deviceId = fdp.ConsumeRandomLengthString();
204 std::string bundleName = fdp.ConsumeRandomLengthString();
205 sptr<IRemoteObject> callback(new MockDistributedSched());
206 WantParams wantParams;
207
208 PARCEL_WRITE_HELPER_NORET(dataParcel, String, str);
209 PARCEL_WRITE_HELPER_NORET(dataParcel, String, str);
210 PARCEL_WRITE_HELPER_NORET(dataParcel, Int32, int32Data);
211 PARCEL_WRITE_HELPER_NORET(dataParcel, RemoteObject, callback);
212 PARCEL_WRITE_HELPER_NORET(dataParcel, Parcelable, &wantParams);
213 DistributedSchedService::GetInstance().ContinueMissionInner(dataParcel, reply);
214 DistributedSchedService::GetInstance().ContinueLocalMission(deviceId, int32Data, callback, wantParams);
215 DistributedSchedService::GetInstance().ContinueRemoteMission(deviceId, deviceId, int32Data, callback, wantParams);
216 DistributedSchedService::GetInstance().ContinueMission(deviceId, deviceId, int32Data, callback, wantParams);
217 }
218
ContinueMissionOfBundleNameInnerFuzzTest(const uint8_t * data,size_t size)219 void ContinueMissionOfBundleNameInnerFuzzTest(const uint8_t* data, size_t size)
220 {
221 if ((data == nullptr) || (size < sizeof(int32_t))) {
222 return;
223 }
224 FuzzUtil::MockPermission();
225 MessageParcel dataParcel;
226 MessageParcel reply;
227 MessageOption option;
228 FuzzedDataProvider fdp(data, size);
229 std::string str = fdp.ConsumeRandomLengthString();
230 std::string deviceId = fdp.ConsumeRandomLengthString();
231 std::string bundleName = fdp.ConsumeRandomLengthString();
232 sptr<IRemoteObject> callback(new MockDistributedSched());
233 WantParams wantParams;
234
235 PARCEL_WRITE_HELPER_NORET(dataParcel, String, str);
236 PARCEL_WRITE_HELPER_NORET(dataParcel, String, str);
237 PARCEL_WRITE_HELPER_NORET(dataParcel, String, str);
238 PARCEL_WRITE_HELPER_NORET(dataParcel, RemoteObject, callback);
239 PARCEL_WRITE_HELPER_NORET(dataParcel, Parcelable, &wantParams);
240 DistributedSchedService::GetInstance().ContinueMissionOfBundleNameInner(dataParcel, reply);
241 DistributedSchedService::GetInstance().ContinueRemoteMission(deviceId, deviceId, bundleName,
242 callback, wantParams);
243 DistributedSchedService::GetInstance().ProcessContinueLocalMission(deviceId, deviceId, bundleName,
244 callback, wantParams);
245 DistributedSchedService::GetInstance().ProcessContinueRemoteMission(deviceId, deviceId, bundleName,
246 callback, wantParams);
247 }
248
GetMissionInfosInnerFuzzTest(const uint8_t * data,size_t size)249 void GetMissionInfosInnerFuzzTest(const uint8_t* data, size_t size)
250 {
251 if ((data == nullptr) || (size < sizeof(int32_t))) {
252 return;
253 }
254 FuzzUtil::MockPermission();
255 MessageParcel dataParcel;
256 MessageParcel reply;
257 MessageOption option;
258 FuzzedDataProvider fdp(data, size);
259 int32_t int32Data = fdp.ConsumeIntegral<int32_t>();
260 std::string str = fdp.ConsumeRandomLengthString();
261
262 PARCEL_WRITE_HELPER_NORET(dataParcel, String16, Str8ToStr16(str));
263 PARCEL_WRITE_HELPER_NORET(dataParcel, Int32, int32Data);
264 DistributedSchedService::GetInstance().GetMissionInfosInner(dataParcel, reply);
265 }
266
RegisterMissionListenerInnerFuzzTest(const uint8_t * data,size_t size)267 void RegisterMissionListenerInnerFuzzTest(const uint8_t* data, size_t size)
268 {
269 if ((data == nullptr) || (size < sizeof(int32_t))) {
270 return;
271 }
272 FuzzUtil::MockPermission();
273 MessageParcel dataParcel;
274 MessageParcel reply;
275 MessageOption option;
276 Want want;
277 FuzzedDataProvider fdp(data, size);
278 int32_t missionId = fdp.ConsumeIntegral<int32_t>();
279 uint32_t uint32Data = fdp.ConsumeIntegral<uint32_t>();
280 std::string str = fdp.ConsumeRandomLengthString();
281 sptr<IRemoteObject> obj(new MockDistributedSched());
282
283 PARCEL_WRITE_HELPER_NORET(dataParcel, String16, Str8ToStr16(str));
284 PARCEL_WRITE_HELPER_NORET(dataParcel, RemoteObject, obj);
285 DistributedSchedService::GetInstance().RegisterMissionListenerInner(dataParcel, reply);
286 DistributedSchedService::GetInstance().ContinueLocalMissionDealFreeInstall(want, missionId, str, obj);
287 DistributedSchedService::GetInstance().ContinueAbilityWithTimeout(str, missionId, obj, uint32Data);
288 }
289
UnRegisterMissionListenerInnerFuzzTest(const uint8_t * data,size_t size)290 void UnRegisterMissionListenerInnerFuzzTest(const uint8_t* data, size_t size)
291 {
292 if ((data == nullptr) || (size < sizeof(int32_t))) {
293 return;
294 }
295 FuzzUtil::MockPermission();
296 MessageParcel dataParcel;
297 MessageParcel reply;
298 MessageOption option;
299 FuzzedDataProvider fdp(data, size);
300 std::string str = fdp.ConsumeRandomLengthString();
301 sptr<IRemoteObject> obj(new MockDistributedSched());
302
303 PARCEL_WRITE_HELPER_NORET(dataParcel, String16, Str8ToStr16(str));
304 PARCEL_WRITE_HELPER_NORET(dataParcel, RemoteObject, obj);
305 DistributedSchedService::GetInstance().UnRegisterMissionListenerInner(dataParcel, reply);
306 }
307
StartSyncRemoteMissionsInnerFuzzTest(const uint8_t * data,size_t size)308 void StartSyncRemoteMissionsInnerFuzzTest(const uint8_t* data, size_t size)
309 {
310 if ((data == nullptr) || (size < sizeof(int32_t))) {
311 return;
312 }
313 FuzzUtil::MockPermission();
314 MessageParcel dataParcel;
315 MessageParcel reply;
316 MessageOption option;
317 FuzzedDataProvider fdp(data, size);
318 bool boolData = fdp.ConsumeBool();
319 std::string str = fdp.ConsumeRandomLengthString();
320 int64_t int64Data = static_cast<int64_t>(GetU32Data(data, size));
321
322 PARCEL_WRITE_HELPER_NORET(dataParcel, String16, Str8ToStr16(str));
323 PARCEL_WRITE_HELPER_NORET(dataParcel, Bool, boolData);
324 PARCEL_WRITE_HELPER_NORET(dataParcel, Int64, int64Data);
325 DistributedSchedService::GetInstance().StartSyncRemoteMissionsInner(dataParcel, reply);
326 }
327
StopSyncRemoteMissionsInnerFuzzTest(const uint8_t * data,size_t size)328 void StopSyncRemoteMissionsInnerFuzzTest(const uint8_t* data, size_t size)
329 {
330 if ((data == nullptr) || (size < sizeof(int32_t))) {
331 return;
332 }
333 FuzzUtil::MockPermission();
334 MessageParcel dataParcel;
335 MessageParcel reply;
336 MessageOption option;
337 std::string str(reinterpret_cast<const char*>(data), size);
338
339 PARCEL_WRITE_HELPER_NORET(dataParcel, String16, Str8ToStr16(str));
340 DistributedSchedService::GetInstance().StopSyncRemoteMissionsInner(dataParcel, reply);
341
342 Want want;
343 CallerInfo callerInfo;
344 IDistributedSched::AccountInfo accountInfo;
345 int32_t flag = *(reinterpret_cast<const int32_t*>(data));
346 DistributedSchedService::GetInstance().CheckTargetPermission(want, callerInfo, accountInfo, flag, true);
347 }
348
GetRemoteMissionSnapshotInfoInnerFuzzTest(const uint8_t * data,size_t size)349 void GetRemoteMissionSnapshotInfoInnerFuzzTest(const uint8_t* data, size_t size)
350 {
351 if ((data == nullptr) || (size < sizeof(int32_t))) {
352 return;
353 }
354 FuzzUtil::MockPermission();
355 MessageParcel dataParcel;
356 MessageParcel reply;
357 MessageOption option;
358 FuzzedDataProvider fdp(data, size);
359 int32_t missionId = fdp.ConsumeIntegral<int32_t>();
360 std::string networkId = fdp.ConsumeRandomLengthString();
361
362 dataParcel.WriteString(networkId);
363 dataParcel.WriteInt32(missionId);
364 DistributedSchedService::GetInstance().GetRemoteMissionSnapshotInfoInner(dataParcel, reply);
365 DistributedSchedService::GetInstance().DurationStart(networkId, networkId);
366 }
367
StartRemoteAbilityByCallInnerFuzzTest(const uint8_t * data,size_t size)368 void StartRemoteAbilityByCallInnerFuzzTest(const uint8_t* data, size_t size)
369 {
370 if ((data == nullptr) || (size < sizeof(int32_t))) {
371 return;
372 }
373 FuzzUtil::MockPermission();
374 MessageParcel dataParcel;
375 MessageParcel reply;
376 MessageOption option;
377 Want want;
378 sptr<IRemoteObject> obj(new MockDistributedSched());
379 FuzzedDataProvider fdp(data, size);
380 int32_t int32Data = fdp.ConsumeIntegral<int32_t>();
381 uint32_t uint32Data = fdp.ConsumeIntegral<uint32_t>();
382
383 PARCEL_WRITE_HELPER_NORET(dataParcel, Parcelable, &want);
384 PARCEL_WRITE_HELPER_NORET(dataParcel, RemoteObject, obj);
385 PARCEL_WRITE_HELPER_NORET(dataParcel, Int32, int32Data);
386 PARCEL_WRITE_HELPER_NORET(dataParcel, Int32, int32Data);
387 PARCEL_WRITE_HELPER_NORET(dataParcel, Uint32, uint32Data);
388 DistributedSchedService::GetInstance().StartRemoteAbilityByCallInner(dataParcel, reply);
389 DistributedSchedService::GetInstance().SetWantForContinuation(want, int32Data);
390 }
391
ReleaseRemoteAbilityInnerFuzzTest(const uint8_t * data,size_t size)392 void ReleaseRemoteAbilityInnerFuzzTest(const uint8_t* data, size_t size)
393 {
394 if ((data == nullptr) || (size < sizeof(int32_t))) {
395 return;
396 }
397 FuzzUtil::MockPermission();
398 MessageParcel dataParcel;
399 MessageParcel reply;
400 MessageOption option;
401 sptr<IRemoteObject> connect(new MockDistributedSched());
402 Want want;
403 AppExecFwk::ElementName element;
404 CallerInfo callerInfo;
405 std::string deviceId(reinterpret_cast<const char*>(data), size);
406
407 PARCEL_WRITE_HELPER_NORET(dataParcel, RemoteObject, connect);
408 PARCEL_WRITE_HELPER_NORET(dataParcel, Parcelable, &element);
409 DistributedSchedService::GetInstance().ReleaseRemoteAbilityInner(dataParcel, reply);
410 callerInfo.uid = ONE;
411 DistributedSchedService::GetInstance().CheckDistributedConnectLocked(callerInfo);
412 DistributedSchedService::GetInstance().DecreaseConnectLocked(ONE);
413 DistributedSchedService::GetInstance().RemoteConnectAbilityMappingLocked(connect, deviceId,
414 deviceId, element, callerInfo, TargetComponent::HARMONY_COMPONENT);
415 DistributedSchedService::GetInstance().NotifyProcessDied(deviceId, callerInfo, TargetComponent::HARMONY_COMPONENT);
416 DistributedSchedService::GetInstance().ProcessDeviceOffline(deviceId);
417 }
418
GetDistributedComponentListInnerFuzzTest(const uint8_t * data,size_t size)419 int32_t GetDistributedComponentListInnerFuzzTest(const uint8_t* data, size_t size)
420 {
421 if ((data == nullptr) || (size < sizeof(int32_t))) {
422 return INVALID_PARAMETERS_ERR;
423 }
424 FuzzUtil::MockPermission();
425 MessageParcel dataParcel;
426 MessageParcel reply;
427 std::vector<std::string> distributedComponents;
428 FuzzedDataProvider fdp(data, size);
429 int32_t int32Data = fdp.ConsumeIntegral<int32_t>();
430 std::string str = fdp.ConsumeRandomLengthString();
431 distributedComponents.push_back(str);
432 PARCEL_WRITE_HELPER(reply, Int32, int32Data);
433 PARCEL_WRITE_HELPER(reply, StringVector, distributedComponents);
434
435 DistributedSchedService::GetInstance().GetDistributedComponentListInner(dataParcel, reply);
436 return ERR_OK;
437 }
438
StartRemoteFreeInstallInnerFuzzTest(const uint8_t * data,size_t size)439 void StartRemoteFreeInstallInnerFuzzTest(const uint8_t* data, size_t size)
440 {
441 if ((data == nullptr) || (size < sizeof(int32_t))) {
442 return;
443 }
444 FuzzUtil::MockPermission();
445 MessageParcel dataParcel;
446 MessageParcel reply;
447 MessageOption option;
448 FuzzedDataProvider fdp(data, size);
449 int32_t int32Data = fdp.ConsumeIntegral<int32_t>();
450 uint32_t uint32Data = fdp.ConsumeIntegral<uint32_t>();
451 sptr<IRemoteObject> obj(new MockDistributedSched());
452 Want want;
453
454 PARCEL_WRITE_HELPER_NORET(dataParcel, Parcelable, &want);
455 PARCEL_WRITE_HELPER_NORET(dataParcel, Int32, int32Data);
456 PARCEL_WRITE_HELPER_NORET(dataParcel, Int32, int32Data);
457 PARCEL_WRITE_HELPER_NORET(dataParcel, Uint32, uint32Data);
458 PARCEL_WRITE_HELPER_NORET(dataParcel, RemoteObject, obj);
459 DistributedSchedService::GetInstance().StartRemoteFreeInstallInner(dataParcel, reply);
460 DistributedSchedService::GetInstance().ProcessCallResult(obj, obj);
461 }
462
StartRemoteShareFormInnerFuzzTest(const uint8_t * data,size_t size)463 void StartRemoteShareFormInnerFuzzTest(const uint8_t* data, size_t size)
464 {
465 if ((data == nullptr) || (size < sizeof(int32_t))) {
466 return;
467 }
468 FuzzUtil::MockPermission();
469 int32_t code = static_cast<uint32_t>(IDSchedInterfaceCode::START_REMOTE_SHARE_FORM);
470 MessageParcel dataParcel;
471 MessageParcel reply;
472 MessageOption option;
473 std::string str(reinterpret_cast<const char*>(data), size);
474 Want want;
475 dataParcel.WriteInterfaceToken(DMS_STUB_INTERFACE_TOKEN);
476 PARCEL_WRITE_HELPER_NORET(dataParcel, String, str);
477 PARCEL_WRITE_HELPER_NORET(dataParcel, Parcelable, &want);
478 DistributedSchedService::GetInstance().OnRemoteRequest(code, dataParcel, reply, option);
479 }
480
StopRemoteExtensionAbilityInnerFuzzTest(const uint8_t * data,size_t size)481 void StopRemoteExtensionAbilityInnerFuzzTest(const uint8_t* data, size_t size)
482 {
483 if ((data == nullptr) || (size < sizeof(int32_t))) {
484 return;
485 }
486 FuzzUtil::MockPermission();
487 MessageParcel dataParcel;
488 MessageParcel reply;
489 MessageOption option;
490 Want want;
491 FuzzedDataProvider fdp(data, size);
492 int32_t callerUid = fdp.ConsumeIntegral<int32_t>();
493 int32_t serviceType = fdp.ConsumeIntegral<int32_t>();
494 uint32_t accessToken = fdp.ConsumeIntegral<uint32_t>();
495 dataParcel.WriteParcelable(&want);
496 dataParcel.WriteInt32(callerUid);
497 dataParcel.WriteUint32(accessToken);
498 dataParcel.WriteInt32(serviceType);
499 DistributedSchedService::GetInstance().StopRemoteExtensionAbilityInner(dataParcel, reply);
500
501 CallerInfo callerInfo;
502 std::string localDeviceId(reinterpret_cast<const char*>(data), size);
503 DistributedSchedService::GetInstance().GetCallerInfo(localDeviceId, callerUid, accessToken, callerInfo);
504 DistributedSchedService::GetInstance().CheckDeviceIdFromRemote(localDeviceId, localDeviceId, localDeviceId);
505 }
506
RegisterOnListenerInnerFuzzTest(const uint8_t * data,size_t size)507 void RegisterOnListenerInnerFuzzTest(const uint8_t* data, size_t size)
508 {
509 if ((data == nullptr) || (size < sizeof(int32_t))) {
510 return;
511 }
512 FuzzUtil::MockPermission();
513 MessageParcel dataParcel;
514 MessageParcel reply;
515 MessageOption option;
516 std::string str(reinterpret_cast<const char*>(data), size);
517 sptr<IRemoteObject> obj(new MockDistributedSched());
518
519 PARCEL_WRITE_HELPER_NORET(dataParcel, String, str);
520 PARCEL_WRITE_HELPER_NORET(dataParcel, RemoteObject, obj);
521 DistributedSchedService::GetInstance().RegisterOnListenerInner(dataParcel, reply);
522 DistributedSchedService::GetInstance().HandleLocalCallerDied(obj);
523 DistributedSchedService::GetInstance().RemoveCallerComponent(obj);
524 DistributedSchedService::GetInstance().RemoveConnectAbilityInfo(str);
525 DistributedSchedService::GetInstance().DumpConnectInfo(str);
526 }
527
RegisterOffListenerInnerFuzzTest(const uint8_t * data,size_t size)528 void RegisterOffListenerInnerFuzzTest(const uint8_t* data, size_t size)
529 {
530 if ((data == nullptr) || (size < sizeof(int32_t))) {
531 return;
532 }
533 FuzzUtil::MockPermission();
534 MessageParcel dataParcel;
535 MessageParcel reply;
536 MessageOption option;
537 std::string str(reinterpret_cast<const char*>(data), size);
538 sptr<IRemoteObject> obj(new MockDistributedSched());
539
540 PARCEL_WRITE_HELPER_NORET(dataParcel, String, str);
541 PARCEL_WRITE_HELPER_NORET(dataParcel, RemoteObject, obj);
542 DistributedSchedService::GetInstance().RegisterOffListenerInner(dataParcel, reply);
543 }
544
RegisterDSchedEventListenerInnerFuzzTest(const uint8_t * data,size_t size)545 void RegisterDSchedEventListenerInnerFuzzTest(const uint8_t* data, size_t size)
546 {
547 if ((data == nullptr) || (size < sizeof(int32_t))) {
548 return;
549 }
550 FuzzUtil::MockPermission();
551 MessageParcel dataParcel;
552 MessageParcel reply;
553 MessageOption option;
554 uint8_t uint8Data = *(reinterpret_cast<const uint8_t*>(data));
555 sptr<IRemoteObject> obj(new MockDistributedSched());
556
557 PARCEL_WRITE_HELPER_NORET(dataParcel, Uint8, uint8Data);
558 PARCEL_WRITE_HELPER_NORET(dataParcel, RemoteObject, obj);
559 DistributedSchedService::GetInstance().RegisterDSchedEventListenerInner(dataParcel, reply);
560 }
561
UnRegisterDSchedEventListenerInnerFuzzTest(const uint8_t * data,size_t size)562 void UnRegisterDSchedEventListenerInnerFuzzTest(const uint8_t* data, size_t size)
563 {
564 if ((data == nullptr) || (size < sizeof(int32_t))) {
565 return;
566 }
567 FuzzUtil::MockPermission();
568 MessageParcel dataParcel;
569 MessageParcel reply;
570 MessageOption option;
571 uint8_t uint8Data = *(reinterpret_cast<const uint8_t*>(data));
572 sptr<IRemoteObject> obj(new MockDistributedSched());
573
574 PARCEL_WRITE_HELPER_NORET(dataParcel, Uint8, uint8Data);
575 PARCEL_WRITE_HELPER_NORET(dataParcel, RemoteObject, obj);
576 DistributedSchedService::GetInstance().UnRegisterDSchedEventListenerInner(dataParcel, reply);
577 }
578
SetMissionContinueStateInnerFuzzTest(const uint8_t * data,size_t size)579 void SetMissionContinueStateInnerFuzzTest(const uint8_t* data, size_t size)
580 {
581 if ((data == nullptr) || (size < sizeof(int32_t))) {
582 return;
583 }
584 FuzzUtil::MockPermission();
585 MessageParcel dataParcel;
586 MessageParcel reply;
587 MessageOption option;
588 FuzzedDataProvider fdp(data, size);
589 int32_t missionId = fdp.ConsumeIntegral<int32_t>();
590 int32_t state = fdp.ConsumeIntegral<int32_t>();
591 int32_t timeout = fdp.ConsumeIntegral<int32_t>();
592
593 dataParcel.WriteInt32(missionId);
594 dataParcel.WriteInt32(state);
595 DistributedSchedService::GetInstance().SetMissionContinueStateInner(dataParcel, reply);
596 DistributedSchedService::GetInstance().RemoveContinuationTimeout(missionId);
597 DistributedSchedService::GetInstance().SetContinuationTimeout(missionId, timeout);
598 DistributedSchedService::GetInstance().GetContinuaitonDevice(missionId);
599 }
600
StartAbilityFromRemoteInnerFuzzTest(const uint8_t * data,size_t size)601 void StartAbilityFromRemoteInnerFuzzTest(const uint8_t* data, size_t size)
602 {
603 if ((data == nullptr) || (size < sizeof(int32_t))) {
604 return;
605 }
606 FuzzUtil::MockPermission();
607 MessageParcel dataParcel;
608 MessageParcel reply;
609 MessageOption option;
610 DistributedWant dstbWant;
611 AppExecFwk::CompatibleAbilityInfo compatibleAbilityInfo;
612 FuzzedDataProvider fdp(data, size);
613 int32_t int32Data = fdp.ConsumeIntegral<int32_t>();
614 std::string str = fdp.ConsumeRandomLengthString();
615 std::vector<std::string> strVector = {str};
616
617 PARCEL_WRITE_HELPER_NORET(dataParcel, Parcelable, &dstbWant);
618 PARCEL_WRITE_HELPER_NORET(dataParcel, Parcelable, &compatibleAbilityInfo);
619 PARCEL_WRITE_HELPER_NORET(dataParcel, Int32, int32Data);
620 PARCEL_WRITE_HELPER_NORET(dataParcel, Int32, int32Data);
621 PARCEL_WRITE_HELPER_NORET(dataParcel, String, str);
622 PARCEL_WRITE_HELPER_NORET(dataParcel, Int32, int32Data);
623 PARCEL_WRITE_HELPER_NORET(dataParcel, StringVector, strVector);
624 PARCEL_WRITE_HELPER_NORET(dataParcel, String, str);
625 DistributedSchedService::GetInstance().StartAbilityFromRemoteInner(dataParcel, reply);
626 }
627
SendResultFromRemoteInnerFuzzTest(const uint8_t * data,size_t size)628 void SendResultFromRemoteInnerFuzzTest(const uint8_t* data, size_t size)
629 {
630 if ((data == nullptr) || (size < sizeof(int32_t))) {
631 return;
632 }
633 FuzzUtil::MockPermission();
634 MessageParcel dataParcel;
635 MessageParcel reply;
636 MessageOption option;
637 AppExecFwk::CompatibleAbilityInfo compatibleAbilityInfo;
638 FuzzedDataProvider fdp(data, size);
639 int32_t int32Data = fdp.ConsumeIntegral<int32_t>();
640 std::string str = fdp.ConsumeRandomLengthString();
641 std::vector<std::string> strVector = {str};
642 DistributedWant dstbWant;
643
644 PARCEL_WRITE_HELPER_NORET(dataParcel, Parcelable, &dstbWant);
645 PARCEL_WRITE_HELPER_NORET(dataParcel, Int32, int32Data);
646 PARCEL_WRITE_HELPER_NORET(dataParcel, Int32, int32Data);
647 PARCEL_WRITE_HELPER_NORET(dataParcel, String, str);
648 PARCEL_WRITE_HELPER_NORET(dataParcel, Int32, int32Data);
649 PARCEL_WRITE_HELPER_NORET(dataParcel, StringVector, strVector);
650 PARCEL_WRITE_HELPER_NORET(dataParcel, String, str);
651 PARCEL_WRITE_HELPER_NORET(dataParcel, Int32, int32Data);
652 PARCEL_WRITE_HELPER_NORET(dataParcel, String, str);
653 DistributedSchedService::GetInstance().SendResultFromRemoteInner(dataParcel, reply);
654 }
655
NotifyDSchedEventResultFromRemoteInnerFuzzTest(const uint8_t * data,size_t size)656 void NotifyDSchedEventResultFromRemoteInnerFuzzTest(const uint8_t* data, size_t size)
657 {
658 if ((data == nullptr) || (size < sizeof(int32_t))) {
659 return;
660 }
661 FuzzUtil::MockPermission();
662 MessageParcel dataParcel;
663 MessageParcel reply;
664 MessageOption option;
665 int32_t int32Data = *(reinterpret_cast<const int32_t*>(data));
666 std::string str(reinterpret_cast<const char*>(data), size);
667
668 PARCEL_WRITE_HELPER_NORET(dataParcel, String, str);
669 PARCEL_WRITE_HELPER_NORET(dataParcel, Int32, int32Data);
670 DistributedSchedService::GetInstance().NotifyDSchedEventResultFromRemoteInner(dataParcel, reply);
671 }
672
NotifyContinuationResultFromRemoteInnerFuzzTest(const uint8_t * data,size_t size)673 void NotifyContinuationResultFromRemoteInnerFuzzTest(const uint8_t* data, size_t size)
674 {
675 if ((data == nullptr) || (size < sizeof(int32_t))) {
676 return;
677 }
678 FuzzUtil::MockPermission();
679 DmsContinueTime::GetInstance().Init();
680 MessageParcel dataParcel;
681 MessageParcel reply;
682 MessageOption option;
683 AppExecFwk::CompatibleAbilityInfo compatibleAbilityInfo;
684 FuzzedDataProvider fdp(data, size);
685 bool boolData = fdp.ConsumeBool();
686 int32_t int32Data = fdp.ConsumeIntegral<int32_t>();
687 std::string str = fdp.ConsumeRandomLengthString();
688
689 PARCEL_WRITE_HELPER_NORET(dataParcel, Int32, int32Data);
690 PARCEL_WRITE_HELPER_NORET(dataParcel, Bool, boolData);
691 PARCEL_WRITE_HELPER_NORET(dataParcel, String, str);
692 DistributedSchedService::GetInstance().NotifyContinuationResultFromRemoteInner(dataParcel, reply);
693 }
694
ConnectAbilityFromRemoteInnerFuzzTest(const uint8_t * data,size_t size)695 void ConnectAbilityFromRemoteInnerFuzzTest(const uint8_t* data, size_t size)
696 {
697 if ((data == nullptr) || (size < sizeof(int32_t))) {
698 return;
699 }
700 FuzzUtil::MockPermission();
701 MessageParcel dataParcel;
702 MessageParcel reply;
703 MessageOption option;
704 AppExecFwk::CompatibleAbilityInfo compatibleAbilityInfo;
705 FuzzedDataProvider fdp(data, size);
706 int32_t int32Data = fdp.ConsumeIntegral<int32_t>();
707 std::string str = fdp.ConsumeRandomLengthString();
708 std::vector<std::string> strVector = {str};
709 DistributedWant dstbWant;
710 const sptr<IRemoteObject> connect(new MockDistributedSched());
711
712 PARCEL_WRITE_HELPER_NORET(dataParcel, Parcelable, &dstbWant);
713 PARCEL_WRITE_HELPER_NORET(dataParcel, Parcelable, &compatibleAbilityInfo);
714 PARCEL_WRITE_HELPER_NORET(dataParcel, RemoteObject, connect);
715 PARCEL_WRITE_HELPER_NORET(dataParcel, Int32, int32Data);
716 PARCEL_WRITE_HELPER_NORET(dataParcel, Int32, int32Data);
717 PARCEL_WRITE_HELPER_NORET(dataParcel, String, str);
718 PARCEL_WRITE_HELPER_NORET(dataParcel, Int32, int32Data);
719 PARCEL_WRITE_HELPER_NORET(dataParcel, StringVector, strVector);
720 PARCEL_WRITE_HELPER_NORET(dataParcel, String, str);
721 PARCEL_WRITE_HELPER_NORET(dataParcel, String, str);
722 DistributedSchedService::GetInstance().ConnectAbilityFromRemoteInner(dataParcel, reply);
723 }
724
DisconnectAbilityFromRemoteInnerFuzzTest(const uint8_t * data,size_t size)725 void DisconnectAbilityFromRemoteInnerFuzzTest(const uint8_t* data, size_t size)
726 {
727 if ((data == nullptr) || (size < sizeof(int32_t))) {
728 return;
729 }
730 FuzzUtil::MockPermission();
731 MessageParcel dataParcel;
732 MessageParcel reply;
733 MessageOption option;
734 AppExecFwk::CompatibleAbilityInfo compatibleAbilityInfo;
735 FuzzedDataProvider fdp(data, size);
736 int32_t int32Data = fdp.ConsumeIntegral<int32_t>();
737 std::string str = fdp.ConsumeRandomLengthString();
738
739 sptr<IRemoteObject> connect(new MockDistributedSched());
740 PARCEL_WRITE_HELPER_NORET(dataParcel, RemoteObject, connect);
741 PARCEL_WRITE_HELPER_NORET(dataParcel, Int32, int32Data);
742 PARCEL_WRITE_HELPER_NORET(dataParcel, String, str);
743 DistributedSchedService::GetInstance().DisconnectAbilityFromRemoteInner(dataParcel, reply);
744 DistributedSchedService::GetInstance().ProcessCallerDied(connect, int32Data);
745 DistributedSchedService::GetInstance().ProcessCalleeDied(connect);
746 }
747
NotifyProcessDiedFromRemoteInnerFuzzTest(const uint8_t * data,size_t size)748 void NotifyProcessDiedFromRemoteInnerFuzzTest(const uint8_t* data, size_t size)
749 {
750 if ((data == nullptr) || (size < sizeof(int32_t))) {
751 return;
752 }
753 FuzzUtil::MockPermission();
754 MessageParcel dataParcel;
755 MessageParcel reply;
756 MessageOption option;
757 FuzzedDataProvider fdp(data, size);
758 int32_t int32Data = fdp.ConsumeIntegral<int32_t>();
759 std::string str = fdp.ConsumeRandomLengthString();
760
761 PARCEL_WRITE_HELPER_NORET(dataParcel, Int32, int32Data);
762 PARCEL_WRITE_HELPER_NORET(dataParcel, Int32, int32Data);
763 PARCEL_WRITE_HELPER_NORET(dataParcel, String, str);
764 DistributedSchedService::GetInstance().NotifyProcessDiedFromRemoteInner(dataParcel, reply);
765 }
766
GetContinueInfoInnerFuzzTest(const uint8_t * data,size_t size)767 void GetContinueInfoInnerFuzzTest(const uint8_t* data, size_t size)
768 {
769 if ((data == nullptr) || (size < sizeof(int32_t))) {
770 return;
771 }
772 FuzzUtil::MockPermission();
773 MessageParcel dataParcel;
774 MessageParcel reply;
775 MessageOption option;
776 std::string str(reinterpret_cast<const char*>(data), size);
777
778 PARCEL_WRITE_HELPER_NORET(dataParcel, String, str);
779 PARCEL_WRITE_HELPER_NORET(dataParcel, String, str);
780 DistributedSchedService::GetInstance().GetContinueInfoInner(dataParcel, reply);
781 }
782
NotifyMissionsChangedFromRemoteInnerFuzzTest(const uint8_t * data,size_t size)783 void NotifyMissionsChangedFromRemoteInnerFuzzTest(const uint8_t* data, size_t size)
784 {
785 if ((data == nullptr) || (size < sizeof(int32_t))) {
786 return;
787 }
788 FuzzUtil::MockPermission();
789 MessageParcel dataParcel;
790 MessageParcel reply;
791 MessageOption option;
792 FuzzedDataProvider fdp(data, size);
793 int32_t int32Data = fdp.ConsumeIntegral<int32_t>();
794 std::string str = fdp.ConsumeRandomLengthString();
795 std::vector<DstbMissionInfo> missionInfos;
796 CallerInfo callerInfo;
797 DistributedWant dstbWant;
798
799 PARCEL_WRITE_HELPER_NORET(dataParcel, Parcelable, &dstbWant);
800 if (!DstbMissionInfo::WriteDstbMissionInfosToParcel(dataParcel, missionInfos)) {
801 return;
802 }
803 PARCEL_WRITE_HELPER_NORET(dataParcel, Int32, int32Data);
804 PARCEL_WRITE_HELPER_NORET(dataParcel, String, str);
805 PARCEL_WRITE_HELPER_NORET(dataParcel, Int32, int32Data);
806 PARCEL_WRITE_HELPER_NORET(dataParcel, Int32, int32Data);
807 PARCEL_WRITE_HELPER_NORET(dataParcel, Int32, int32Data);
808 DistributedSchedService::GetInstance().NotifyMissionsChangedFromRemoteInner(dataParcel, reply);
809 }
810
ReleaseAbilityFromRemoteInnerFuzzTest(const uint8_t * data,size_t size)811 void ReleaseAbilityFromRemoteInnerFuzzTest(const uint8_t* data, size_t size)
812 {
813 if ((data == nullptr) || (size < sizeof(int32_t))) {
814 return;
815 }
816 FuzzUtil::MockPermission();
817 MessageParcel dataParcel;
818 MessageParcel reply;
819 MessageOption option;
820 sptr<IRemoteObject> connect(new MockDistributedSched());
821 AppExecFwk::ElementName element;
822 Want want;
823 const CallerInfo callerInfo;
824 FuzzedDataProvider fdp(data, size);
825 int32_t int32Data = fdp.ConsumeIntegral<int32_t>();
826 std::string str = fdp.ConsumeRandomLengthString();
827
828 PARCEL_WRITE_HELPER_NORET(dataParcel, RemoteObject, connect);
829 PARCEL_WRITE_HELPER_NORET(dataParcel, Parcelable, &element);
830 PARCEL_WRITE_HELPER_NORET(dataParcel, String, str);
831 PARCEL_WRITE_HELPER_NORET(dataParcel, String, str);
832 DistributedSchedService::GetInstance().ReleaseAbilityFromRemoteInner(dataParcel, reply);
833 DistributedSchedService::GetInstance().TryStartRemoteAbilityByCall(want, connect, callerInfo);
834 DistributedSchedService::GetInstance().SaveCallerComponent(want, connect, callerInfo);
835 DistributedSchedService::GetInstance().SaveConnectToken(want, connect);
836 DistributedSchedService::GetInstance().NotifyStateChanged(int32Data, element, connect);
837 DistributedSchedService::GetInstance().SetCleanMissionFlag(want, int32Data);
838 }
839
NotifyStateChangedFromRemoteInnerFuzzTest(const uint8_t * data,size_t size)840 void NotifyStateChangedFromRemoteInnerFuzzTest(const uint8_t* data, size_t size)
841 {
842 if ((data == nullptr) || (size < sizeof(int32_t))) {
843 return;
844 }
845 FuzzUtil::MockPermission();
846 MessageParcel dataParcel;
847 MessageParcel reply;
848 MessageOption option;
849 const AppExecFwk::ElementName element;
850 sptr<IRemoteObject> connect(new MockDistributedSched());
851 FuzzedDataProvider fdp(data, size);
852 int32_t int32Data = fdp.ConsumeIntegral<int32_t>();
853 std::string str = fdp.ConsumeRandomLengthString();
854
855 PARCEL_WRITE_HELPER_NORET(dataParcel, Int32, int32Data);
856 PARCEL_WRITE_HELPER_NORET(dataParcel, Int32, int32Data);
857 PARCEL_WRITE_HELPER_NORET(dataParcel, Parcelable, &element);
858 DistributedSchedService::GetInstance().NotifyStateChangedFromRemoteInner(dataParcel, reply);
859 DistributedSchedService::GetInstance().NotifyApp(connect, element, int32Data);
860 }
861
StartFreeInstallFromRemoteInnerFuzzTest(const uint8_t * data,size_t size)862 void StartFreeInstallFromRemoteInnerFuzzTest(const uint8_t* data, size_t size)
863 {
864 if ((data == nullptr) || (size < sizeof(int32_t))) {
865 return;
866 }
867 FuzzUtil::MockPermission();
868 MessageParcel dataParcel;
869 MessageParcel reply;
870 MessageOption option;
871 FuzzedDataProvider fdp(data, size);
872 int32_t int32Data = fdp.ConsumeIntegral<int32_t>();
873 std::string str = fdp.ConsumeRandomLengthString();
874 int64_t int64Data = static_cast<int64_t>(GetU32Data(data, size));
875 std::vector<std::string> strVector = {str};
876 DistributedWant dstbWant;
877
878 PARCEL_WRITE_HELPER_NORET(dataParcel, Parcelable, &dstbWant);
879 PARCEL_WRITE_HELPER_NORET(dataParcel, Int32, int32Data);
880 PARCEL_WRITE_HELPER_NORET(dataParcel, String, str);
881 PARCEL_WRITE_HELPER_NORET(dataParcel, Int32, int32Data);
882 PARCEL_WRITE_HELPER_NORET(dataParcel, StringVector, strVector);
883 PARCEL_WRITE_HELPER_NORET(dataParcel, String, str);
884 PARCEL_WRITE_HELPER_NORET(dataParcel, Int64, int64Data);
885 PARCEL_WRITE_HELPER_NORET(dataParcel, Parcelable, &dstbWant);
886 PARCEL_WRITE_HELPER_NORET(dataParcel, String, str);
887 DistributedSchedService::GetInstance().StartFreeInstallFromRemoteInner(dataParcel, reply);
888 }
889
NotifyCompleteFreeInstallFromRemoteInnerFuzzTest(const uint8_t * data,size_t size)890 void NotifyCompleteFreeInstallFromRemoteInnerFuzzTest(const uint8_t* data, size_t size)
891 {
892 if ((data == nullptr) || (size < sizeof(int32_t))) {
893 return;
894 }
895 FuzzUtil::MockPermission();
896 MessageParcel dataParcel;
897 MessageParcel reply;
898 MessageOption option;
899 FuzzedDataProvider fdp(data, size);
900 int32_t int32Data = fdp.ConsumeIntegral<int32_t>();
901 int64_t int64Data = static_cast<int64_t>(GetU32Data(data, size));
902
903 PARCEL_WRITE_HELPER_NORET(dataParcel, Int64, int64Data);
904 PARCEL_WRITE_HELPER_NORET(dataParcel, Int32, int32Data);
905 DistributedSchedService::GetInstance().NotifyCompleteFreeInstallFromRemoteInner(dataParcel, reply);
906 }
907
GetDSchedEventInfoInnerFuzzTest(const uint8_t * data,size_t size)908 void GetDSchedEventInfoInnerFuzzTest(const uint8_t* data, size_t size)
909 {
910 if ((data == nullptr) || (size < sizeof(int32_t))) {
911 return;
912 }
913 FuzzUtil::MockPermission();
914 MessageParcel dataParcel;
915 MessageParcel reply;
916 MessageOption option;
917 int32_t int32Data = *(reinterpret_cast<const int32_t*>(data)) % DMS_ALL;
918
919 PARCEL_WRITE_HELPER_NORET(dataParcel, Int32, int32Data);
920 DistributedSchedService::GetInstance().GetDSchedEventInfoInner(dataParcel, reply);
921 }
922
StartAbilityByCallFromRemoteInnerFuzzTest(const uint8_t * data,size_t size)923 void StartAbilityByCallFromRemoteInnerFuzzTest(const uint8_t* data, size_t size)
924 {
925 if ((data == nullptr) || (size < sizeof(int32_t))) {
926 return;
927 }
928 FuzzUtil::MockPermission();
929 MessageParcel dataParcel;
930 MessageParcel reply;
931 MessageOption option;
932 FuzzedDataProvider fdp(data, size);
933 int32_t int32Data = fdp.ConsumeIntegral<int32_t>();
934 std::string str = fdp.ConsumeRandomLengthString();
935 std::vector<std::string> strVector = {str};
936 DistributedWant dstbWant;
937 sptr<IRemoteObject> connect(new MockDistributedSched());
938
939 PARCEL_WRITE_HELPER_NORET(dataParcel, RemoteObject, connect);
940 PARCEL_WRITE_HELPER_NORET(dataParcel, Int32, int32Data);
941 PARCEL_WRITE_HELPER_NORET(dataParcel, Int32, int32Data);
942 PARCEL_WRITE_HELPER_NORET(dataParcel, String, str);
943 PARCEL_WRITE_HELPER_NORET(dataParcel, Int32, int32Data);
944 PARCEL_WRITE_HELPER_NORET(dataParcel, StringVector, strVector);
945 PARCEL_WRITE_HELPER_NORET(dataParcel, String, str);
946 PARCEL_WRITE_HELPER_NORET(dataParcel, String, str);
947 PARCEL_WRITE_HELPER_NORET(dataParcel, Parcelable, &dstbWant);
948 DistributedSchedService::GetInstance().StartAbilityByCallFromRemoteInner(dataParcel, reply);
949 DistributedSchedService::GetInstance().ProcessConnectDied(connect);
950 DistributedSchedService::GetInstance().DisconnectEachRemoteAbilityLocked(str, str, connect);
951 }
952
StartSyncMissionsFromRemoteInnerFuzzTest(const uint8_t * data,size_t size)953 void StartSyncMissionsFromRemoteInnerFuzzTest(const uint8_t* data, size_t size)
954 {
955 if ((data == nullptr) || (size < sizeof(int32_t))) {
956 return;
957 }
958 FuzzUtil::MockPermission();
959 MessageParcel dataParcel;
960 MessageParcel reply;
961 MessageOption option;
962 FuzzedDataProvider fdp(data, size);
963 int32_t int32Data = fdp.ConsumeIntegral<int32_t>();
964 std::string str = fdp.ConsumeRandomLengthString();
965
966 PARCEL_WRITE_HELPER_NORET(dataParcel, Int32, int32Data);
967 PARCEL_WRITE_HELPER_NORET(dataParcel, Int32, int32Data);
968 PARCEL_WRITE_HELPER_NORET(dataParcel, Int32, int32Data);
969 PARCEL_WRITE_HELPER_NORET(dataParcel, String, str);
970 PARCEL_WRITE_HELPER_NORET(dataParcel, Int32, int32Data);
971 PARCEL_WRITE_HELPER_NORET(dataParcel, String, str);
972 PARCEL_WRITE_HELPER_NORET(dataParcel, Int32, int32Data);
973 DistributedSchedService::GetInstance().StartSyncMissionsFromRemoteInner(dataParcel, reply);
974 }
975
StopSyncMissionsFromRemoteInnerFuzzTest(const uint8_t * data,size_t size)976 void StopSyncMissionsFromRemoteInnerFuzzTest(const uint8_t* data, size_t size)
977 {
978 if ((data == nullptr) || (size < sizeof(int32_t))) {
979 return;
980 }
981 FuzzUtil::MockPermission();
982 MessageParcel dataParcel;
983 MessageParcel reply;
984 MessageOption option;
985 FuzzedDataProvider fdp(data, size);
986 int32_t int32Data = fdp.ConsumeIntegral<int32_t>();
987 std::string str = fdp.ConsumeRandomLengthString();
988
989 PARCEL_WRITE_HELPER_NORET(dataParcel, Int32, int32Data);
990 PARCEL_WRITE_HELPER_NORET(dataParcel, Int32, int32Data);
991 PARCEL_WRITE_HELPER_NORET(dataParcel, Int32, int32Data);
992 PARCEL_WRITE_HELPER_NORET(dataParcel, String, str);
993 PARCEL_WRITE_HELPER_NORET(dataParcel, Int32, int32Data);
994 PARCEL_WRITE_HELPER_NORET(dataParcel, String, str);
995 PARCEL_WRITE_HELPER_NORET(dataParcel, Int32, int32Data);
996
997 DistributedSchedService::GetInstance().StopSyncMissionsFromRemoteInner(dataParcel, reply);
998 }
999
StartShareFormFromRemoteInnerFuzzTest(const uint8_t * data,size_t size)1000 void StartShareFormFromRemoteInnerFuzzTest(const uint8_t* data, size_t size)
1001 {
1002 if ((data == nullptr) || (size < sizeof(int32_t))) {
1003 return;
1004 }
1005 FuzzUtil::MockPermission();
1006 MessageParcel dataParcel;
1007 MessageParcel reply;
1008 std::string str(reinterpret_cast<const char*>(data), size);
1009 DistributedWant dstbWant;
1010 PARCEL_WRITE_HELPER_NORET(dataParcel, String, str);
1011 PARCEL_WRITE_HELPER_NORET(dataParcel, Parcelable, &dstbWant);
1012 DistributedSchedService::GetInstance().StartShareFormFromRemoteInner(dataParcel, reply);
1013 }
1014
StopExtensionAbilityFromRemoteInnerFuzzTest(const uint8_t * data,size_t size)1015 void StopExtensionAbilityFromRemoteInnerFuzzTest(const uint8_t* data, size_t size)
1016 {
1017 if ((data == nullptr) || (size < sizeof(int32_t))) {
1018 return;
1019 }
1020 FuzzUtil::MockPermission();
1021 MessageParcel dataParcel;
1022 MessageParcel reply;
1023 MessageOption option;
1024 FuzzedDataProvider fdp(data, size);
1025 int32_t int32Data = fdp.ConsumeIntegral<int32_t>();
1026 std::string str = fdp.ConsumeRandomLengthString();
1027 std::vector<std::string> strVector = {str};
1028 DistributedWant dstbWant;
1029
1030 PARCEL_WRITE_HELPER_NORET(dataParcel, Parcelable, &dstbWant);
1031 PARCEL_WRITE_HELPER_NORET(dataParcel, Int32, int32Data);
1032 PARCEL_WRITE_HELPER_NORET(dataParcel, Int32, int32Data);
1033 PARCEL_WRITE_HELPER_NORET(dataParcel, String, str);
1034 PARCEL_WRITE_HELPER_NORET(dataParcel, Int32, int32Data);
1035 PARCEL_WRITE_HELPER_NORET(dataParcel, StringVector, strVector);
1036 PARCEL_WRITE_HELPER_NORET(dataParcel, String, str);
1037 PARCEL_WRITE_HELPER_NORET(dataParcel, String, str);
1038 DistributedSchedService::GetInstance().StopExtensionAbilityFromRemoteInner(dataParcel, reply);
1039 }
1040
StopAbilityFromRemoteInnerFuzzTest(const uint8_t * data,size_t size)1041 void StopAbilityFromRemoteInnerFuzzTest(const uint8_t* data, size_t size)
1042 {
1043 if ((data == nullptr) || (size < sizeof(int32_t))) {
1044 return;
1045 }
1046 FuzzUtil::MockPermission();
1047 MessageParcel dataParcel;
1048 MessageParcel reply;
1049 FuzzedDataProvider fdp(data, size);
1050 int32_t int32Data = fdp.ConsumeIntegral<int32_t>();
1051 std::string str = fdp.ConsumeRandomLengthString();
1052 std::vector<std::string> strVector = {str};
1053 DistributedWant dstbWant;
1054
1055 PARCEL_WRITE_HELPER_NORET(dataParcel, Parcelable, &dstbWant);
1056 PARCEL_WRITE_HELPER_NORET(dataParcel, Int32, int32Data);
1057 PARCEL_WRITE_HELPER_NORET(dataParcel, Int32, int32Data);
1058 PARCEL_WRITE_HELPER_NORET(dataParcel, String, str);
1059 PARCEL_WRITE_HELPER_NORET(dataParcel, Int32, int32Data);
1060 PARCEL_WRITE_HELPER_NORET(dataParcel, StringVector, strVector);
1061 PARCEL_WRITE_HELPER_NORET(dataParcel, String, str);
1062 PARCEL_WRITE_HELPER_NORET(dataParcel, String, str);
1063 DistributedSchedService::GetInstance().StopAbilityFromRemoteInner(dataParcel, reply);
1064 }
1065
CollabMissionInnerFuzzTest(const uint8_t * data,size_t size)1066 void CollabMissionInnerFuzzTest(const uint8_t* data, size_t size)
1067 {
1068 if ((data == nullptr) || (size < sizeof(int32_t))) {
1069 return;
1070 }
1071 FuzzUtil::MockPermission();
1072 MessageParcel dataParcel;
1073 MessageParcel reply;
1074 FuzzedDataProvider fdp(data, size);
1075 CollabMessage massage;
1076 ConnectOpt opt;
1077 int32_t collabSessionId = fdp.ConsumeIntegral<int32_t>();
1078 std::string srcSocketName = fdp.ConsumeRandomLengthString();
1079 std::string collabToken = fdp.ConsumeRandomLengthString();
1080 PARCEL_WRITE_HELPER_NORET(dataParcel, Int32, collabSessionId);
1081 PARCEL_WRITE_HELPER_NORET(dataParcel, String, srcSocketName);
1082 dataParcel.WriteParcelable(&massage);
1083 dataParcel.WriteParcelable(&massage);
1084 dataParcel.WriteParcelable(&opt);
1085 PARCEL_WRITE_HELPER_NORET(dataParcel, String, collabToken);
1086 DistributedSchedService::GetInstance().CollabMissionInner(dataParcel, reply);
1087 }
1088
NotifyCloseCollabSessionInnerFuzzTest(const uint8_t * data,size_t size)1089 void NotifyCloseCollabSessionInnerFuzzTest(const uint8_t* data, size_t size)
1090 {
1091 if ((data == nullptr) || (size < sizeof(int32_t))) {
1092 return;
1093 }
1094 FuzzUtil::MockPermission();
1095 MessageParcel dataParcel;
1096 MessageParcel reply;
1097 FuzzedDataProvider fdp(data, size);
1098 std::string tokenId = fdp.ConsumeRandomLengthString();
1099 dataParcel.WriteString(tokenId);
1100 DistributedSchedService::GetInstance().NotifyCloseCollabSessionInner(dataParcel, reply);
1101 }
1102
GetSinkCollabVersionInnerFuzzTest(const uint8_t * data,size_t size)1103 void GetSinkCollabVersionInnerFuzzTest(const uint8_t* data, size_t size)
1104 {
1105 if ((data == nullptr) || (size < sizeof(int32_t))) {
1106 return;
1107 }
1108 FuzzUtil::MockPermission();
1109 MessageParcel dataParcel;
1110 MessageParcel reply;
1111 FuzzedDataProvider fdp(data, size);
1112 int32_t collabSessionId = fdp.ConsumeIntegral<int32_t>();
1113 std::string sinkDeviceId = fdp.ConsumeRandomLengthString();
1114 std::string collabToken = fdp.ConsumeRandomLengthString();
1115 PARCEL_WRITE_HELPER_NORET(dataParcel, Int32, collabSessionId);
1116 PARCEL_WRITE_HELPER_NORET(dataParcel, String, sinkDeviceId);
1117 PARCEL_WRITE_HELPER_NORET(dataParcel, String, collabToken);
1118 dataParcel.WriteRemoteObject(nullptr);
1119 DistributedSchedService::GetInstance().GetSinkCollabVersionInner(dataParcel, reply);
1120 }
1121
NotifyRejectReasonFuzzTest(const uint8_t * data,size_t size)1122 void NotifyRejectReasonFuzzTest(const uint8_t* data, size_t size)
1123 {
1124 if ((data == nullptr) || (size < sizeof(int32_t))) {
1125 return;
1126 }
1127 FuzzUtil::MockPermission();
1128 MessageParcel dataParcel;
1129 MessageParcel reply;
1130 FuzzedDataProvider fdp(data, size);
1131 std::string token = fdp.ConsumeRandomLengthString();
1132 std::string reason = fdp.ConsumeRandomLengthString();
1133 dataParcel.WriteString(token);
1134 dataParcel.WriteString(reason);
1135 DistributedSchedService::GetInstance().NotifyRejectReason(dataParcel, reply);
1136 }
1137
NotifyCollabPrepareResultInnerFuzzTest(const uint8_t * data,size_t size)1138 void NotifyCollabPrepareResultInnerFuzzTest(const uint8_t* data, size_t size)
1139 {
1140 if ((data == nullptr) || (size < sizeof(int32_t))) {
1141 return;
1142 }
1143 FuzzUtil::MockPermission();
1144 MessageParcel dataParcel;
1145 MessageParcel reply;
1146 FuzzedDataProvider fdp(data, size);
1147 std::string collabToken = fdp.ConsumeRandomLengthString();
1148 int32_t ret = fdp.ConsumeIntegral<int32_t>();
1149 int32_t sinkCollabSessionId = fdp.ConsumeIntegral<int32_t>();
1150 std::string sinkSocketName = fdp.ConsumeRandomLengthString();
1151 dataParcel.WriteString(collabToken);
1152 dataParcel.WriteInt32(ret);
1153 dataParcel.WriteInt32(sinkCollabSessionId);
1154 dataParcel.WriteString(sinkSocketName);
1155 dataParcel.WriteRemoteObject(nullptr);
1156 DistributedSchedService::GetInstance().NotifyCollabPrepareResultInner(dataParcel, reply);
1157 }
1158
FuzzTest(const uint8_t * data,size_t size)1159 void FuzzTest(const uint8_t* data, size_t size)
1160 {
1161 CollabMissionInnerFuzzTest(data, size);
1162 NotifyCloseCollabSessionInnerFuzzTest(data, size);
1163 GetSinkCollabVersionInnerFuzzTest(data, size);
1164 NotifyRejectReasonFuzzTest(data, size);
1165 NotifyCollabPrepareResultInnerFuzzTest(data, size);
1166 }
1167 }
1168 }
1169
1170 /* Fuzzer entry point */
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)1171 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
1172 {
1173 OHOS::DistributedSchedule::StartRemoteAbilityInnerFuzzTest(data, size);
1174 OHOS::DistributedSchedule::ConnectRemoteAbilityInnerFuzzTest(data, size);
1175 OHOS::DistributedSchedule::DisconnectRemoteAbilityInnerFuzzTest(data, size);
1176 OHOS::DistributedSchedule::StartContinuationInnerFuzzTest(data, size);
1177 OHOS::DistributedSchedule::NotifyCompleteContinuationInnerFuzzTest(data, size);
1178 OHOS::DistributedSchedule::ContinueMissionInnerFuzzTest(data, size);
1179 OHOS::DistributedSchedule::ContinueMissionOfBundleNameInnerFuzzTest(data, size);
1180 OHOS::DistributedSchedule::GetMissionInfosInnerFuzzTest(data, size);
1181 OHOS::DistributedSchedule::RegisterMissionListenerInnerFuzzTest(data, size);
1182 OHOS::DistributedSchedule::UnRegisterMissionListenerInnerFuzzTest(data, size);
1183 OHOS::DistributedSchedule::StartSyncRemoteMissionsInnerFuzzTest(data, size);
1184 OHOS::DistributedSchedule::StopSyncRemoteMissionsInnerFuzzTest(data, size);
1185 OHOS::DistributedSchedule::GetRemoteMissionSnapshotInfoInnerFuzzTest(data, size);
1186 OHOS::DistributedSchedule::StartRemoteAbilityByCallInnerFuzzTest(data, size);
1187 OHOS::DistributedSchedule::ReleaseRemoteAbilityInnerFuzzTest(data, size);
1188 OHOS::DistributedSchedule::GetDistributedComponentListInnerFuzzTest(data, size);
1189 OHOS::DistributedSchedule::StartRemoteFreeInstallInnerFuzzTest(data, size);
1190 OHOS::DistributedSchedule::StartRemoteShareFormInnerFuzzTest(data, size);
1191 OHOS::DistributedSchedule::StopRemoteExtensionAbilityInnerFuzzTest(data, size);
1192 OHOS::DistributedSchedule::RegisterOnListenerInnerFuzzTest(data, size);
1193 OHOS::DistributedSchedule::RegisterOffListenerInnerFuzzTest(data, size);
1194 OHOS::DistributedSchedule::RegisterDSchedEventListenerInnerFuzzTest(data, size);
1195 OHOS::DistributedSchedule::UnRegisterDSchedEventListenerInnerFuzzTest(data, size);
1196 OHOS::DistributedSchedule::SetMissionContinueStateInnerFuzzTest(data, size);
1197 OHOS::DistributedSchedule::StartAbilityFromRemoteInnerFuzzTest(data, size);
1198 OHOS::DistributedSchedule::SendResultFromRemoteInnerFuzzTest(data, size);
1199 OHOS::DistributedSchedule::NotifyDSchedEventResultFromRemoteInnerFuzzTest(data, size);
1200 OHOS::DistributedSchedule::NotifyContinuationResultFromRemoteInnerFuzzTest(data, size);
1201 OHOS::DistributedSchedule::ConnectAbilityFromRemoteInnerFuzzTest(data, size);
1202 OHOS::DistributedSchedule::DisconnectAbilityFromRemoteInnerFuzzTest(data, size);
1203 OHOS::DistributedSchedule::NotifyProcessDiedFromRemoteInnerFuzzTest(data, size);
1204 OHOS::DistributedSchedule::GetContinueInfoInnerFuzzTest(data, size);
1205 OHOS::DistributedSchedule::NotifyMissionsChangedFromRemoteInnerFuzzTest(data, size);
1206 OHOS::DistributedSchedule::ReleaseAbilityFromRemoteInnerFuzzTest(data, size);
1207 OHOS::DistributedSchedule::NotifyStateChangedFromRemoteInnerFuzzTest(data, size);
1208 OHOS::DistributedSchedule::StartFreeInstallFromRemoteInnerFuzzTest(data, size);
1209 OHOS::DistributedSchedule::NotifyCompleteFreeInstallFromRemoteInnerFuzzTest(data, size);
1210 OHOS::DistributedSchedule::GetDSchedEventInfoInnerFuzzTest(data, size);
1211 OHOS::DistributedSchedule::StartAbilityByCallFromRemoteInnerFuzzTest(data, size);
1212 OHOS::DistributedSchedule::StartSyncMissionsFromRemoteInnerFuzzTest(data, size);
1213 OHOS::DistributedSchedule::StopSyncMissionsFromRemoteInnerFuzzTest(data, size);
1214 OHOS::DistributedSchedule::StartShareFormFromRemoteInnerFuzzTest(data, size);
1215 OHOS::DistributedSchedule::StopExtensionAbilityFromRemoteInnerFuzzTest(data, size);
1216 OHOS::DistributedSchedule::StopAbilityFromRemoteInnerFuzzTest(data, size);
1217 OHOS::DistributedSchedule::FuzzTest(data, size);
1218 return 0;
1219 }