• 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 #define private public
17 #include <cstddef>
18 #include <cstdint>
19 #include <fuzzer/FuzzedDataProvider.h>
20 
21 #include "uninstall_data_mgr_storage_rdb.h"
22 
23 #include "bmsuninstalldatamgr_fuzzer.h"
24 #include "bms_fuzztest_util.h"
25 
26 using namespace OHOS::AppExecFwk;
27 using namespace OHOS::AppExecFwk::BMSFuzzTestUtil;
28 namespace OHOS {
GenerateUninstallBundleInfo(FuzzedDataProvider & fdp,UninstallBundleInfo & uninstallbundleInfo)29 void GenerateUninstallBundleInfo(FuzzedDataProvider& fdp, UninstallBundleInfo &uninstallbundleInfo)
30 {
31     uninstallbundleInfo.appId = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH);
32     uninstallbundleInfo.appIdentifier = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH);
33     uninstallbundleInfo.appProvisionType = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH);
34     uninstallbundleInfo.bundleType = static_cast<BundleType>(fdp.ConsumeIntegralInRange<uint8_t>(0, CODE_MAX_FOUR));
35     uninstallbundleInfo.appId = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH);
36     uninstallbundleInfo.extensionDirs = GenerateStringArray(fdp);
37 }
38 
DoSomethingInterestingWithMyAPI(const uint8_t * data,size_t size)39 bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size)
40 {
41     UninstallDataMgrStorageRdb uninstallDataMgrStorageRdb;
42     FuzzedDataProvider fdp(data, size);
43     std::string bundleName;
44     UninstallBundleInfo uninstallbundleInfo;
45     GenerateUninstallBundleInfo(fdp, uninstallbundleInfo);
46     std::map<std::string, std::string> datas;
47     std::map<std::string, UninstallBundleInfo> uninstallBundleInfos;
48     uninstallDataMgrStorageRdb.TransformStrToInfo(datas, uninstallBundleInfos);
49 
50     uninstallDataMgrStorageRdb.UpdateUninstallBundleInfo(bundleName, uninstallbundleInfo);
51     uninstallDataMgrStorageRdb.GetAllUninstallBundleInfo(uninstallBundleInfos);
52     uninstallDataMgrStorageRdb.DeleteUninstallBundleInfo(bundleName);
53 
54     bundleName = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH);
55     GenerateMap(fdp, datas);
56     uninstallDataMgrStorageRdb.TransformStrToInfo(datas, uninstallBundleInfos);
57     UninstallBundleInfo uninstallbundleInfo2;
58     uninstallDataMgrStorageRdb.UpdateUninstallBundleInfo(bundleName, uninstallbundleInfo2);
59     uninstallDataMgrStorageRdb.DeleteUninstallBundleInfo(bundleName);
60 
61     uninstallDataMgrStorageRdb.rdbDataManager_ = nullptr;
62     uninstallDataMgrStorageRdb.UpdateUninstallBundleInfo(bundleName, uninstallbundleInfo2);
63     uninstallDataMgrStorageRdb.GetAllUninstallBundleInfo(uninstallBundleInfos);
64     uninstallDataMgrStorageRdb.TransformStrToInfo(datas, uninstallBundleInfos);
65     uninstallDataMgrStorageRdb.DeleteUninstallBundleInfo(bundleName);
66     return true;
67 }
68 }
69 
70 // Fuzzer entry point.
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)71 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
72 {
73     /* Run your code on data */
74     OHOS::DoSomethingInterestingWithMyAPI(data, size);
75     return 0;
76 }
77