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 "abilityecologicalrulemgrservicefirst_fuzzer.h"
17
18 #include <cstddef>
19 #include <cstdint>
20 #include <fuzzer/FuzzedDataProvider.h>
21
22 #define private public
23 #include "ability_ecological_rule_mgr_service.h"
24 #undef private
25
26 #include "ability_fuzz_util.h"
27
28 using namespace OHOS::AAFwk;
29 using namespace OHOS::AppExecFwk;
30
31 namespace OHOS {
32 namespace {
33 constexpr size_t STRING_MAX_LENGTH = 128;
34 }
DoSomethingInterestingWithMyAPI(const uint8_t * data,size_t size)35 bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size)
36 {
37 auto client = std::make_shared<AbilityEcologicalRuleMgrServiceClient>();
38 wptr<IRemoteObject> object;
39 Want want;
40 AbilityCallerInfo callerInfo;
41 int32_t type;
42 vector<AbilityInfo> abilityInfos;
43 AbilityInfo info;
44 vector<AppExecFwk::ExtensionAbilityInfo> extInfos;
45 AbilityExperienceRule rule;
46 FuzzedDataProvider fdp(data, size);
47 client->ConnectService();
48 client->CheckConnectService();
49 client->OnRemoteSaDied(object);
50 type = fdp.ConsumeIntegral<int32_t>();
51 size_t arraySize = fdp.ConsumeIntegralInRange<size_t>(0, STRING_MAX_LENGTH);
52 for (size_t i = 0; i < arraySize; ++i) {
53 AbilityFuzzUtil::GetRandomAbilityInfo(fdp, info);
54 abilityInfos.emplace_back(info);
55 }
56 client->EvaluateResolveInfos(want, callerInfo, type, abilityInfos, extInfos);
57 AbilityFuzzUtil::GetRandomAbilityExperienceRule(fdp, rule);
58 client->QueryStartExperience(want, callerInfo, rule);
59
60 return true;
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 // Run your code on data.
68 OHOS::DoSomethingInterestingWithMyAPI(data, size);
69 return 0;
70 }