• 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 "distributedschedstubten_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 
GetWifiStatusInnerFuzzTest(const uint8_t * data,size_t size)39 void GetWifiStatusInnerFuzzTest(const uint8_t* data, size_t size)
40 {
41     if ((data == nullptr) || (size < sizeof(int32_t))) {
42         return;
43     }
44     FuzzUtil::MockPermission();
45     MessageParcel dataParcel;
46     MessageParcel reply;
47 
48     FuzzedDataProvider fdp(data, size);
49     bool isSuccess = fdp.ConsumeBool();
50     int32_t sessionId = fdp.ConsumeIntegral<int32_t>();
51     std::string devId = fdp.ConsumeRandomLengthString();
52     dataParcel.WriteString16(Str8ToStr16(devId));
53     dataParcel.WriteInt32(sessionId);
54     dataParcel.WriteBool(isSuccess);
55     DistributedSchedService::GetInstance().GetWifiStatusInner(dataParcel, reply);
56 }
57 
IsNewCollabVersionFuzzTest(const uint8_t * data,size_t size)58 void IsNewCollabVersionFuzzTest(const uint8_t* data, size_t size)
59 {
60     if ((data == nullptr) || (size < sizeof(int32_t))) {
61         return;
62     }
63     FuzzUtil::MockPermission();
64     FuzzedDataProvider fdp(data, size);
65     std::string remoteDeviceId = fdp.ConsumeRandomLengthString();
66     DistributedSchedService::GetInstance().IsNewCollabVersion(remoteDeviceId);
67 }
68 }
69 }
70 
71 /* Fuzzer entry point */
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)72 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
73 {
74     OHOS::DistributedSchedule::IsNewCollabVersionFuzzTest(data, size);
75     OHOS::DistributedSchedule::GetWifiStatusInnerFuzzTest(data, size);
76     return 0;
77 }
78