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 #include <iostream>
17 #include <cstddef>
18 #include <cstdint>
19 #include <cstring>
20 #include "audio_utils.h"
21 #include "audio_log.h"
22 #include "../fuzz_utils.h"
23
24 #include "resource_manager_adapter.h"
25
26 namespace OHOS {
27 namespace AudioStandard {
28 using namespace std;
29
30 FuzzUtils &g_fuzzUtils = FuzzUtils::GetInstance();
31 const size_t FUZZ_INPUT_SIZE_THRESHOLD = 10;
32
33 typedef void (*TestFuncs)();
34
ReleaseSystemResourceManagerFuzzTest()35 void ReleaseSystemResourceManagerFuzzTest()
36 {
37 auto resourceManagerAdapter = std::make_shared<ResourceManagerAdapter>();
38 if (resourceManagerAdapter == nullptr) {
39 return;
40 }
41 resourceManagerAdapter->resourceManager_ = Global::Resource::GetSystemResourceManagerNoSandBox();
42 resourceManagerAdapter->resConfig_ = Global::Resource::CreateResConfig();
43 resourceManagerAdapter->ReleaseSystemResourceManager();
44 }
45
46 vector<TestFuncs> g_testFuncs = {
47 ReleaseSystemResourceManagerFuzzTest,
48 };
49
50 } // namespace AudioStandard
51 } // namesapce OHOS
52
53 /* Fuzzer entry point */
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)54 extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
55 {
56 if (size < OHOS::AudioStandard::FUZZ_INPUT_SIZE_THRESHOLD) {
57 return 0;
58 }
59
60 OHOS::AudioStandard::g_fuzzUtils.fuzzTest(data, size, OHOS::AudioStandard::g_testFuncs);
61 return 0;
62 }
63