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 "abilitychildprocessrecordfirst_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_running_record.h"
24 #include "child_process_record.h"
25 #undef private
26
27 #include "child_process_request.h"
28 #include "configuration.h"
29 #include "securec.h"
30
31 using namespace OHOS::AppExecFwk;
32 using namespace OHOS::AAFwk;
33 namespace OHOS {
34 namespace {
35 constexpr size_t STRING_MAX_LENGTH = 128;
36 }
DoSomethingInterestingWithMyAPI(const uint8_t * data,size_t size)37 bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size)
38 {
39 int32_t hostPid;
40 ChildProcessRequest request;
41 std::shared_ptr<AppRunningRecord> hostRecord;
42 std::string stringParam;
43 sptr<IRemoteObject> mainProcessCb;
44 int32_t childProcessCount;
45 bool isStartWithDebug;
46 int32_t recordId;
47 FuzzedDataProvider fdp(data, size);
48 hostPid = fdp.ConsumeIntegral<int32_t>();
49 ChildProcessRecord::CreateChildProcessRecord(hostPid, request, hostRecord);
50 stringParam = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH);
51 childProcessCount = fdp.ConsumeIntegral<int32_t>();
52 isStartWithDebug = fdp.ConsumeBool();
53 ChildProcessRecord::CreateNativeChildProcessRecord(hostPid, stringParam, hostRecord, mainProcessCb,
54 childProcessCount, isStartWithDebug, "");
55 std::shared_ptr<ApplicationInfo> appInfo = std::make_shared<ApplicationInfo>();
56 recordId = fdp.ConsumeIntegral<int32_t>();
57 auto appRecord = std::make_shared<AppRunningRecord>(appInfo, recordId, stringParam);
58 auto childRecord = std::make_shared<ChildProcessRecord>(hostPid, request, appRecord);
59 childRecord->IsNativeSpawnStarted();
60 childRecord->GetProcessType();
61 childRecord->GetEntryFunc();
62 childRecord->GetScheduler();
63 childRecord->SetEntryParams(stringParam);
64 return true;
65 }
66 }
67
68 /* Fuzzer entry point */
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)69 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
70 {
71 // Run your code on data.
72 OHOS::DoSomethingInterestingWithMyAPI(data, size);
73 return 0;
74 }