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 #define private public
17 #include <cstddef>
18 #include <cstdint>
19 #include <fuzzer/FuzzedDataProvider.h>
20
21 #include "bmsfreeinstall_fuzzer.h"
22 #include "bms_ecological_rule_mgr_service_param.h"
23 #include "bms_fuzztest_util.h"
24 #include "bundle_connect_ability_mgr.h"
25 #include "bundle_mgr_interface.h"
26 #include "if_system_ability_manager.h"
27 #include "iservice_registry.h"
28 #include "service_center_connection.h"
29 #include "service_center_status_callback.h"
30 #include "target_ability_info.h"
31 #include "system_ability_definition.h"
32
33 #include "want.h"
34
35 using namespace OHOS::AppExecFwk;
36 using namespace OHOS::AppExecFwk::BMSFuzzTestUtil;
37 namespace OHOS {
DoSomethingInterestingWithMyAPI(const uint8_t * data,size_t size)38 bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size)
39 {
40 #ifdef BUNDLE_FRAMEWORK_FREE_INSTALL
41 FuzzedDataProvider fdp(data, size);
42 BmsExperienceRule bmsExperienceRule;
43 bmsExperienceRule.isAllow = fdp.ConsumeBool();
44 bmsExperienceRule.sceneCode = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH);
45
46 sptr<AAFwk::Want> want = new (std::nothrow) AAFwk::Want();
47 want->SetAction(OHOS::AAFwk::Want::ACTION_HOME);
48 want->AddEntity(OHOS::AAFwk::Want::ENTITY_HOME);
49 want->SetElementName(fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH),
50 fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH),
51 fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH),
52 fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH));
53 bmsExperienceRule.replaceWant = want;
54
55 Parcel parcel;
56 bmsExperienceRule.Marshalling(parcel);
57 auto bmsExperienceRulePtr = bmsExperienceRule.Unmarshalling(parcel);
58 if (bmsExperienceRulePtr != nullptr) {
59 delete bmsExperienceRulePtr;
60 bmsExperienceRulePtr = nullptr;
61 }
62 BmsCallerInfo bmsCallerInfo;
63 bmsCallerInfo.uid = fdp.ConsumeIntegral<int32_t>();
64 bmsCallerInfo.pid = fdp.ConsumeIntegral<int32_t>();
65 bmsCallerInfo.callerAppType = fdp.ConsumeIntegral<int32_t>();
66 bmsCallerInfo.targetAppType = fdp.ConsumeIntegral<int32_t>();
67 bmsCallerInfo.callerModelType = fdp.ConsumeIntegral<int32_t>();
68 bmsCallerInfo.targetLinkType = fdp.ConsumeIntegral<int32_t>();
69 bmsCallerInfo.callerAbilityType = fdp.ConsumeIntegral<int32_t>();
70 bmsCallerInfo.embedded = fdp.ConsumeIntegral<int32_t>();
71 bmsCallerInfo.packageName = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH);
72 bmsCallerInfo.targetAppDistType = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH);
73 bmsCallerInfo.targetLinkFeature = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH);
74 bmsCallerInfo.callerAppProvisionType = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH);
75 bmsCallerInfo.targetAppProvisionType = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH);
76 Parcel parcel2;
77 bmsCallerInfo.ReadFromParcel(parcel2);
78 bmsCallerInfo.Marshalling(parcel2);
79 bmsCallerInfo.ToString();
80 bmsCallerInfo.Unmarshalling(parcel2);
81 auto bmsCallerInfoPtr = bmsCallerInfo.Unmarshalling(parcel2);
82 if (bmsCallerInfoPtr != nullptr) {
83 delete bmsCallerInfoPtr;
84 bmsCallerInfoPtr = nullptr;
85 }
86 #endif
87 return true;
88 }
89 }
90
91 // Fuzzer entry point.
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)92 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
93 {
94 /* Run your code on data */
95 OHOS::DoSomethingInterestingWithMyAPI(data, size);
96 return 0;
97 }