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 "bundle_clone_installer.h"
22
23 #include "bmsbundlecloneinstaller_fuzzer.h"
24 #include "bms_fuzztest_util.h"
25
26 using namespace OHOS::AppExecFwk;
27 using namespace OHOS::AppExecFwk::BMSFuzzTestUtil;
28 namespace OHOS {
DoSomethingInterestingWithMyAPI(const uint8_t * data,size_t size)29 bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size)
30 {
31 BundleCloneInstaller installer;
32 FuzzedDataProvider fdp(data, size);
33
34 std::string emptyBundleName = "";
35 std::string randomBundleName = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH);
36 int32_t appIndex = 1;
37 int32_t randomAppIndex = fdp.ConsumeIntegral<int32_t>();
38 int32_t randomUserId = fdp.ConsumeIntegral<int32_t>();
39
40 installer.InstallCloneApp(emptyBundleName, Constants::START_USERID, appIndex);
41 installer.InstallCloneApp(randomBundleName, Constants::START_USERID, appIndex);
42
43 bool sync = fdp.ConsumeBool();
44
45 installer.ProcessCloneBundleInstall(emptyBundleName, randomUserId, appIndex);
46 installer.ProcessCloneBundleInstall(randomBundleName, Constants::START_USERID, appIndex);
47
48 installer.ProcessCloneBundleUninstall(emptyBundleName, randomUserId, appIndex, sync);
49 installer.ProcessCloneBundleUninstall(randomBundleName, Constants::START_USERID, appIndex, sync);
50 installer.ProcessCloneBundleUninstall(randomBundleName, Constants::START_USERID, randomAppIndex, sync);
51
52 int32_t uid = fdp.ConsumeIntegral<int32_t>();
53 InnerBundleInfo info;
54 installer.UninstallDebugAppSandbox(randomBundleName, uid, appIndex, info);
55 info.baseApplicationInfo_->appProvisionType = true;
56 installer.UninstallDebugAppSandbox(randomBundleName, uid, appIndex, info);
57
58 installer.CreateCloneDataDir(info, randomUserId, uid, randomAppIndex);
59 installer.CreateCloneDataDir(info, Constants::START_USERID, uid, appIndex);
60
61 installer.RemoveCloneDataDir(emptyBundleName, randomUserId, randomAppIndex, sync);
62 installer.RemoveCloneDataDir(randomBundleName, randomUserId, randomAppIndex, sync);
63 installer.RemoveCloneDataDir(randomBundleName, Constants::START_USERID, appIndex, sync);
64
65 installer.CreateEl5Dir(info, Constants::START_USERID, uid, appIndex);
66 installer.CreateEl5Dir(info, randomUserId, uid, randomAppIndex);
67
68 InnerBundleUserInfo userInfo;
69 installer.RemoveEl5Dir(userInfo, uid, Constants::START_USERID, appIndex);
70 installer.RemoveEl5Dir(userInfo, uid, randomUserId, randomAppIndex);
71
72 installer.GetDataMgr();
73
74 BundleEventType bundleEventType = BundleEventType::INSTALL;
75 bool isPreInstallApp = fdp.ConsumeBool();
76 bool isFreeInstallMode = fdp.ConsumeBool();
77 InstallScene preBundleScene = InstallScene::NORMAL;
78 installer.SendBundleSystemEvent(randomBundleName, bundleEventType, randomUserId,
79 randomAppIndex, isPreInstallApp, isFreeInstallMode, preBundleScene, ERR_OK);
80
81 EventInfo eventInfo;
82 installer.GetCallingEventInfo(eventInfo);
83
84 installer.ResetInstallProperties();
85
86 installer.GetAssetAccessGroups(randomBundleName);
87
88 installer.GetDeveloperId(randomBundleName);
89 installer.GetDeveloperId(emptyBundleName);
90
91 return true;
92 }
93 }
94
95 // Fuzzer entry point.
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)96 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
97 {
98 /* Run your code on data */
99 OHOS::DoSomethingInterestingWithMyAPI(data, size);
100 return 0;
101 }