• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_file_util.h"
20 
21 #include "bundlefileutil_fuzzer.h"
22 
23 using namespace OHOS::AppExecFwk;
24 namespace OHOS {
DoSomethingInterestingWithMyAPI(const uint8_t * data,size_t size)25     bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size)
26     {
27         BundleFileUtil fileUtil;
28         std::string bundlePath (reinterpret_cast<const char*>(data), size);
29         std::string realPath (reinterpret_cast<const char*>(data), size);
30         std::vector<std::string> bundlePaths;
31         bundlePaths.push_back(bundlePath);
32         std::vector<std::string> realPaths;
33         realPaths.push_back(realPath);
34         fileUtil.CheckFilePath(bundlePath, realPath);
35         fileUtil.CheckFilePath(bundlePaths, realPaths);
36         std::string fileName (reinterpret_cast<const char*>(data), size);
37         std::string extensionName (reinterpret_cast<const char*>(data), size);
38         fileUtil.CheckFileType(fileName, extensionName);
39         fileUtil.CheckFileName(fileName);
40         fileUtil.CheckFileSize(bundlePath, reinterpret_cast<intptr_t>(data));
41         std::string currentBundlePath (reinterpret_cast<const char*>(data), size);
42         std::vector<std::string> hapFileList;
43         hapFileList.push_back(currentBundlePath);
44         fileUtil.GetHapFilesFromBundlePath(bundlePath, hapFileList);
45         return true;
46     }
47 }
48 
49 // Fuzzer entry point.
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)50 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
51 {
52     // Run your code on data.
53     OHOS::DoSomethingInterestingWithMyAPI(data, size);
54     return 0;
55 }