1 /*
2 * Copyright (c) 2022 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
19 #include "bundle_installer_proxy.h"
20
21 #include "bundleinstallerproxy_fuzzer.h"
22
23 using namespace OHOS::AppExecFwk;
24 namespace OHOS {
25 constexpr size_t U32_AT_SIZE = 4;
26
DoSomethingInterestingWithMyAPI(const uint8_t * data,size_t size)27 bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size)
28 {
29 std::string val(reinterpret_cast<const char*>(data), size);
30 sptr<IRemoteObject> object;
31 BundleInstallerProxy bundleinstallerProxy(object);
32 std::string bundleFilePath = val;
33 InstallParam installParam;
34 sptr<IStatusReceiver> statusReceiver;
35 std::vector<std::string> originHapPaths;
36 bundleinstallerProxy.Install(bundleFilePath, installParam, statusReceiver);
37
38 std::string bundleName = val;
39 bundleinstallerProxy.Recover(bundleName, installParam, statusReceiver);
40
41 std::vector<std::string> bundleFilePaths;
42 bundleFilePaths.push_back(bundleFilePath);
43 bundleinstallerProxy.Install(bundleFilePaths, installParam, statusReceiver);
44
45 bundleinstallerProxy.Uninstall(bundleName, installParam, statusReceiver);
46 std::string modulePackage = val;
47 bundleinstallerProxy.Uninstall(bundleFilePath, modulePackage, installParam, statusReceiver);
48 int32_t dlpType = 0;
49 int32_t userId = 0;
50 int32_t appIndex = 0;
51 bundleinstallerProxy.InstallSandboxApp(bundleName, dlpType, userId, appIndex);
52 bundleinstallerProxy.UninstallSandboxApp(bundleName, appIndex, userId);
53 bundleinstallerProxy.CreateStreamInstaller(installParam, statusReceiver, originHapPaths);
54 bundleinstallerProxy.DestoryBundleStreamInstaller(0);
55 bundleinstallerProxy.StreamInstall(bundleFilePaths, installParam, statusReceiver);
56 return true;
57 }
58 }
59
60 // Fuzzer entry point.
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)61 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
62 {
63 // Run your code on data.
64 if (data == nullptr) {
65 return 0;
66 }
67 if (size < OHOS::U32_AT_SIZE) {
68 return 0;
69 }
70 OHOS::DoSomethingInterestingWithMyAPI(data, size);
71 return 0;
72 }