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
16 #include "extend_resource_manager_host_impl.h"
17 #include "RemoveExtResource_fuzzer.h"
18
19 using namespace OHOS::AppExecFwk;
20 namespace OHOS {
21 namespace {
22 const std::string FUZZTEST_BUNDLE = "com.test.ext.resource";
23 const std::string FUZZTEST_MODULE = "testModule";
24 }
fuzzelRemoveExtResourceCaseOne(const uint8_t * data,size_t size)25 bool fuzzelRemoveExtResourceCaseOne(const uint8_t* data, size_t size)
26 {
27 ExtendResourceManagerHostImpl impl;
28 std::string emptyBundleName;
29 std::vector<std::string> moduleNames;
30 auto ret = impl.RemoveExtResource(emptyBundleName, moduleNames);
31 if (ret == ERR_BUNDLE_MANAGER_BUNDLE_NOT_EXIST) {
32 return true;
33 }
34 return false;
35 }
36
fuzzelRemoveExtResourceCaseTwo(const uint8_t * data,size_t size)37 bool fuzzelRemoveExtResourceCaseTwo(const uint8_t* data, size_t size)
38 {
39 ExtendResourceManagerHostImpl impl;
40 std::vector<std::string> moduleNames;
41 auto ret = impl.RemoveExtResource(FUZZTEST_BUNDLE, moduleNames);
42 if (ret == ERR_EXT_RESOURCE_MANAGER_REMOVE_EXT_RESOURCE_FAILED) {
43 return true;
44 }
45 return false;
46 }
47
fuzzelRemoveExtResourceCaseThree(const uint8_t * data,size_t size)48 bool fuzzelRemoveExtResourceCaseThree(const uint8_t* data, size_t size)
49 {
50 ExtendResourceManagerHostImpl impl;
51 std::vector<std::string> moduleNames;
52 moduleNames.push_back(FUZZTEST_MODULE);
53 auto ret = impl.RemoveExtResource(FUZZTEST_BUNDLE, moduleNames);
54 if (ret == ERR_BUNDLE_MANAGER_BUNDLE_NOT_EXIST) {
55 return true;
56 }
57 return false;
58 }
59 }
60
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)61 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
62 {
63 OHOS::fuzzelRemoveExtResourceCaseOne(data, size);
64 OHOS::fuzzelRemoveExtResourceCaseTwo(data, size);
65 OHOS::fuzzelRemoveExtResourceCaseThree(data, size);
66 return 0;
67 }