• 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 #include "abilityappmgreventfirst_fuzzer.h"
16 
17 #include <cstddef>
18 #include <cstdint>
19 #include <iostream>
20 #include <fuzzer/FuzzedDataProvider.h>
21 
22 #define private public
23 #include "app_mgr_event.h"
24 #undef private
25 
26 #include "configuration.h"
27 #include "securec.h"
28 
29 using namespace OHOS::AppExecFwk;
30 
31 namespace OHOS {
32 namespace {
33 constexpr size_t STRING_MAX_LENGTH = 128;
34 }
35 
DoSomethingInterestingWithMyAPI(const uint8_t * data,size_t size)36 bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size)
37 {
38     auto appInfo = std::make_shared<ApplicationInfo>();
39     appInfo->bundleName = "testBundleName";
40     appInfo->name = "testBundleName";
41     int32_t recordId = 1;
42     std::string processName = "testProcess";
43     std::shared_ptr<AppRunningRecord> callerAppRecord;
44     std::shared_ptr<AppRunningRecord> appRecord;
45     std::shared_ptr<RenderRecord> renderRecord;
46     AAFwk::EventInfo eventInfo;
47     std::string stringParam;
48     EventFwk::CommonEventData eventData;
49     int32_t subReason;
50     FuzzedDataProvider fdp(data, size);
51     stringParam = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH);
52     subReason = fdp.ConsumeIntegral<int32_t>();
53 
54     appRecord = nullptr;
55     AppMgrEventUtil::SendProcessStartFailedEvent(callerAppRecord, appRecord, eventInfo);
56     auto appRecord1 = std::make_shared<AppRunningRecord>(appInfo, recordId, processName);
57     AppMgrEventUtil::SendProcessStartFailedEvent(callerAppRecord, appRecord1, eventInfo);
58 
59     ProcessStartFailedReason reason = ProcessStartFailedReason::APPSPAWN_FAILED;
60     AppMgrEventUtil::SendRenderProcessStartFailedEvent(renderRecord, reason, subReason);
61     return true;
62 }
63 }
64 
65 /* Fuzzer entry point */
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)66 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
67 {
68     // Run your code on data.
69     OHOS::DoSomethingInterestingWithMyAPI(data, size);
70     return 0;
71 }