• 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 "insightintentexecutemanagersecond_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 using namespace OHOS::AAFwk;
28 using namespace OHOS::AppExecFwk;
29 
30 namespace OHOS {
31 namespace {
32 constexpr size_t STRING_MAX_LENGTH = 128;
33 }
DoSomethingInterestingWithMyAPI(const uint8_t * data,size_t size)34 bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size)
35 {
36     uint64_t intentId;
37     std::string callerBundleName;
38     int32_t uid;
39     FuzzedDataProvider fdp(data, size);
40     intentId = fdp.ConsumeIntegral<uint64_t>();
41     callerBundleName = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH);
42     uid = fdp.ConsumeIntegral<int32_t>();
43     DelayedSingleton<InsightIntentExecuteManager>::GetInstance()->GetCallerBundleName(intentId, callerBundleName);
44     DelayedSingleton<InsightIntentExecuteManager>::GetInstance()->SetIntentExemptionInfo(uid);
45     DelayedSingleton<InsightIntentExecuteManager>::GetInstance()->CheckIntentIsExemption(uid);
46     DelayedSingleton<InsightIntentExecuteManager>::GetInstance()->CheckGetInsightIntenInfoPermission();
47     DelayedSingleton<InsightIntentExecuteManager>::GetInstance()->GetAllIntentExemptionInfo();
48 
49     return true;
50 }
51 }
52 
53 /* Fuzzer entry point */
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)54 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
55 {
56     // Run your code on data.
57     OHOS::DoSomethingInterestingWithMyAPI(data, size);
58     return 0;
59 }