1 /*
2 * Copyright (c) 2024 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 #include "storagestatusservice_fuzzer.h"
16 #include "storage/bundle_manager_connector.h"
17 #include "storage/storage_status_service.h"
18 #include "storage_service_log.h"
19 #include "storage_service_errno.h"
20
21 namespace OHOS {
22 namespace StorageManager {
StorageStatusServiceFuzzTest(const uint8_t * data,size_t size)23 bool StorageStatusServiceFuzzTest(const uint8_t *data, size_t size)
24 {
25 if ((data == nullptr) || (size <= sizeof(int64_t))) {
26 return false;
27 }
28 std::shared_ptr<StorageStatusService> service = DelayedSingleton<StorageStatusService>::GetInstance();
29 if (service == nullptr) {
30 return 0;
31 }
32 int32_t userId = *(reinterpret_cast<const int32_t *>(data));
33 std::string pkgName(reinterpret_cast<const char *>(data), size);
34 std::string type(reinterpret_cast<const char *>(data), size);
35 BundleStats bundleStats;
36 StorageStats storageStats;
37 std::vector<std::string> bundleName;
38 std::vector<int64_t> incrementalBackTimes;
39 std::vector<int64_t> pkgFileSizes;
40 std::vector<int64_t> incPkgFileSizes;
41 std::string metaData(reinterpret_cast<const char *>(data), size);
42 int64_t metaData2 = *(reinterpret_cast<const int64_t *>(data));
43 bundleName.push_back(metaData);
44 incrementalBackTimes.push_back(metaData2);
45 pkgFileSizes.push_back(metaData2);
46 incPkgFileSizes.push_back(metaData2);
47 service->GetBundleStats(pkgName, bundleStats, 0, 0);
48 service->GetUserStorageStats(storageStats);
49 service->GetUserStorageStats(userId, storageStats);
50 service->GetUserStorageStatsByType(userId, storageStats, type);
51 service->GetCurrentBundleStats(bundleStats, 0);
52 service->GetBundleStats(pkgName, userId, bundleStats, 0, 0);
53 service->GetBundleStatsForIncrease(userId, bundleName, incrementalBackTimes, pkgFileSizes, incPkgFileSizes);
54 DelayedSingleton<BundleMgrConnector>::GetInstance()->ResetBundleMgrProxy();
55 return true;
56 }
57 } // namespace StorageManager
58 } // namespace OHOS
59
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)60 extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
61 {
62 /* Run your code on data */
63 OHOS::StorageManager::StorageStatusServiceFuzzTest(data, size);
64 return 0;
65 }
66