• 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 <cstddef>
17 #include <cstdint>
18 #include <fuzzer/FuzzedDataProvider.h>
19 
20 #include "app_running_control_rule.h"
21 #include "parcel.h"
22 #include "ipc/extract_param.h"
23 
24 #include "bmsapprunningcontrolrule_fuzzer.h"
25 #include "bms_fuzztest_util.h"
26 
27 using namespace OHOS::AppExecFwk;
28 namespace {
GetRandomAppRunningControlRule(FuzzedDataProvider & fdp,AppRunningControlRule & appRunningControlRule)29 void GetRandomAppRunningControlRule(FuzzedDataProvider& fdp, AppRunningControlRule& appRunningControlRule)
30 {
31     appRunningControlRule.appId = fdp.ConsumeRandomLengthString(BMSFuzzTestUtil::STRING_MAX_LENGTH);
32     appRunningControlRule.controlMessage = fdp.ConsumeRandomLengthString(BMSFuzzTestUtil::STRING_MAX_LENGTH);
33 }
34 }
35 namespace OHOS {
DoSomethingInterestingWithMyAPI(const uint8_t * data,size_t size)36     bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size)
37     {
38         Parcel dataMessageParcel;
39         AppRunningControlRule oldRule;
40 
41         FuzzedDataProvider fdp(data, size);
42         GetRandomAppRunningControlRule(fdp, oldRule);
43         if (!oldRule.Marshalling(dataMessageParcel)) {
44             return false;
45         }
46         auto rulePtr = AppRunningControlRule::Unmarshalling(dataMessageParcel);
47         if (rulePtr == nullptr) {
48             return false;
49         }
50         delete rulePtr;
51         rulePtr = nullptr;
52 
53         AppRunningControlRule readRule;
54         GetRandomAppRunningControlRule(fdp, readRule);
55         bool ret = readRule.ReadFromParcel(dataMessageParcel);
56         ExtractParam extractParam;
57         extractParam.Marshalling(dataMessageParcel);
58         extractParam.ToString();
59         return ret;
60     }
61 }
62 
63 // Fuzzer entry point.
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)64 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
65 {
66     // Run your code on data.
67     OHOS::DoSomethingInterestingWithMyAPI(data, size);
68     return 0;
69 }
70