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 "insightintentexecutemanagerfirst_fuzzer.h"
17
18 #include <cstddef>
19 #include <cstdint>
20 #include <fuzzer/FuzzedDataProvider.h>
21
22 #define private public
23 #include "insight_intent_execute_manager.h"
24 #include "insight_intent_execute_param.h"
25 #undef private
26
27 #include "ability_fuzz_util.h"
28
29 using namespace OHOS::AAFwk;
30 using namespace OHOS::AppExecFwk;
31
32 namespace OHOS {
33 namespace {
34 constexpr size_t STRING_MAX_LENGTH = 128;
35 }
DoSomethingInterestingWithMyAPI(const uint8_t * data,size_t size)36 bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size)
37 {
38 uint64_t key;
39 sptr<IRemoteObject> callerToken;
40 std::shared_ptr<AppExecFwk::InsightIntentExecuteParam> param =
41 std::make_shared<AppExecFwk::InsightIntentExecuteParam>();
42 std::string callerBundleName;
43 bool ignoreAbilityName;
44 Want want;
45 ExtractInsightIntentInfo info;
46 ExtractInsightIntentGenericInfo decoratorInfo;
47 FuzzedDataProvider fdp(data, size);
48 key = fdp.ConsumeIntegral<uint64_t>();
49 callerBundleName = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH);
50 ignoreAbilityName = fdp.ConsumeBool();
51 AbilityFuzzUtil::GetRandomExtractInsightIntentInfo(fdp, info);
52 AbilityFuzzUtil::GetRandomExtractInsightIntentGenericInfo(fdp, decoratorInfo);
53 DelayedSingleton<InsightIntentExecuteManager>::GetInstance()->CheckAndUpdateParam(key, callerToken,
54 param, callerBundleName, ignoreAbilityName);
55 ExecuteMode executeMode = UI_ABILITY_FOREGROUND;
56 DelayedSingleton<InsightIntentExecuteManager>::GetInstance()->CheckAndUpdateWant(want, executeMode,
57 callerBundleName);
58 DelayedSingleton<InsightIntentExecuteManager>::GetInstance()->UpdateEntryDecoratorParams(want, executeMode);
59 executeMode = UI_ABILITY_BACKGROUND;
60 DelayedSingleton<InsightIntentExecuteManager>::GetInstance()->CheckAndUpdateWant(want, executeMode,
61 callerBundleName);
62 DelayedSingleton<InsightIntentExecuteManager>::GetInstance()->UpdateEntryDecoratorParams(want, executeMode);
63 executeMode = UI_EXTENSION_ABILITY;
64 DelayedSingleton<InsightIntentExecuteManager>::GetInstance()->CheckAndUpdateWant(want, executeMode,
65 callerBundleName);
66 DelayedSingleton<InsightIntentExecuteManager>::GetInstance()->UpdateEntryDecoratorParams(want, executeMode);
67 executeMode = SERVICE_EXTENSION_ABILITY;
68 DelayedSingleton<InsightIntentExecuteManager>::GetInstance()->CheckAndUpdateWant(want, executeMode,
69 callerBundleName);
70 DelayedSingleton<InsightIntentExecuteManager>::GetInstance()->UpdateEntryDecoratorParams(want, executeMode);
71 DelayedSingleton<InsightIntentExecuteManager>::GetInstance()->AddWantUirsAndFlagsFromParam(param, want);
72 DelayedSingleton<InsightIntentExecuteManager>::GetInstance()->UpdateFuncDecoratorParams(param, info, want);
73 DelayedSingleton<InsightIntentExecuteManager>::GetInstance()->GetMainElementName(param);
74 DelayedSingleton<InsightIntentExecuteManager>::GetInstance()->UpdatePageDecoratorParams(param, info, want);
75 DelayedSingleton<InsightIntentExecuteManager>::GetInstance()->UpdateEntryDecoratorParams(param, info, want);
76 DelayedSingleton<InsightIntentExecuteManager>::GetInstance()->CheckAndUpdateDecoratorParams(param,
77 decoratorInfo, want);
78
79 return true;
80 }
81 }
82
83 /* Fuzzer entry point */
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)84 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
85 {
86 // Run your code on data.
87 OHOS::DoSomethingInterestingWithMyAPI(data, size);
88 return 0;
89 }