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 "createfd_fuzzer.h"
18
19 using namespace OHOS::AppExecFwk;
20 namespace {
21 const int32_t FD = 0;
22 const std::string FILE_PATH = "data/test";
23 }
24
25 namespace OHOS {
fuzzelCreateFdCaseOne(const uint8_t * data,size_t size)26 bool fuzzelCreateFdCaseOne(const uint8_t* data, size_t size)
27 {
28 ExtendResourceManagerHostImpl impl;
29 int32_t fd = FD;
30 std::string path = FILE_PATH;
31 auto ret = impl.CreateFd(std::string(reinterpret_cast<const char*>(data), size), fd, path);
32 if (ret == ERR_OK) {
33 return true;
34 }
35 return false;
36 }
37
fuzzelCreateFdCaseTwo(const uint8_t * data,size_t size)38 bool fuzzelCreateFdCaseTwo(const uint8_t* data, size_t size)
39 {
40 ExtendResourceManagerHostImpl impl;
41 int32_t fd = FD;
42 std::string path = FILE_PATH;
43 auto ret = impl.CreateFd(std::string(reinterpret_cast<const char*>(data), size), fd, path);
44 if (ret == ERR_OK) {
45 return true;
46 }
47 return false;
48 }
49 }
50
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)51 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
52 {
53 OHOS::fuzzelCreateFdCaseOne(data, size);
54 OHOS::fuzzelCreateFdCaseTwo(data, size);
55 return 0;
56 }