• 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 <set>
19 #include <fuzzer/FuzzedDataProvider.h>
20 #define private public
21 #include "bundle_distributed_manager.h"
22 #include "bmscheckabilityenableinstall_fuzzer.h"
23 #include "bms_fuzztest_util.h"
24 
25 using Want = OHOS::AAFwk::Want;
26 using namespace OHOS::AppExecFwk;
27 using namespace OHOS::AppExecFwk::BMSFuzzTestUtil;
28 namespace OHOS {
29 std::string DEVICE_ID_NORMAL = "deviceId";
30 std::string BUNDLE_NAME_TEST = "com.example.bundlekit.test";
31 std::string MODULE_NAME_MY_APPLICATION = "com.example.MyModuleName";
32 std::string ABILITY_NAME_MY_APPLICATION = "com.example.MyApplication.MainAbility";
DoSomethingInterestingWithMyAPI(const uint8_t * data,size_t size)33 bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size)
34 {
35     std::shared_ptr<BundleDistributedManager> BundleDistributedManager_ =
36         std::make_shared<BundleDistributedManager>();
37     if (BundleDistributedManager_ == nullptr) {
38         return false;
39     }
40     FuzzedDataProvider fdp(data, size);
41     Want want;
42     std::string deviceId = DEVICE_ID_NORMAL;
43     std::string bundleName = BUNDLE_NAME_TEST;
44     std::string moduleName = MODULE_NAME_MY_APPLICATION;
45     std::string abilityName = ABILITY_NAME_MY_APPLICATION;
46     want.SetElementName(deviceId, bundleName, moduleName, abilityName);
47     int32_t missionId = fdp.ConsumeIntegral<int32_t>();
48     int32_t userId = GenerateRandomUser(fdp);
49     sptr<IRemoteObject> callerToken = nullptr;
50     BundleDistributedManager_->CheckAbilityEnableInstall(want, missionId, userId, callerToken);
51 #ifdef BMS_DEVICE_INFO_MANAGER_ENABLE
52     RpcIdResult rpcIdResult;
53     rpcIdResult.retCode = fdp.ConsumeIntegral<int32_t>();
54     rpcIdResult.version = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH);
55     rpcIdResult.transactId = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH);
56     rpcIdResult.resultMsg = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH);
57     BundleDistributedManager_->ComparePcIdString(want, rpcIdResult);
58 #endif
59     return true;
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 }