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 "audioloadadapterdesc_fuzzer.h"
17 #include "securec.h"
18 #include "audio_hdi_fuzzer_common.h"
19
20 using namespace OHOS::Audio;
21 namespace OHOS {
22 namespace Audio {
AudioLoadadapterDescFuzzTest(const uint8_t * data,size_t size)23 bool AudioLoadadapterDescFuzzTest(const uint8_t *data, size_t size)
24 {
25 bool result = false;
26 TestAudioManager *loadAdapterFuzzManager = nullptr;
27 int32_t ret = GetManager(loadAdapterFuzzManager);
28 if (ret < 0 || loadAdapterFuzzManager == nullptr) {
29 HDF_LOGE("%{public}s: GetManager failed \n", __func__);
30 return false;
31 }
32 uint8_t *dataFuzz = const_cast<uint8_t *>(data);
33 struct AudioPort portFuzz = {
34 .dir = *(reinterpret_cast<AudioPortDirection *>(dataFuzz)),
35 .portId = *(reinterpret_cast<uint32_t *>(dataFuzz)),
36 .portName = reinterpret_cast<char *>(dataFuzz),
37 };
38 struct AudioAdapterDescriptor descFuzz = {
39 .adapterName = reinterpret_cast<char *>(dataFuzz),
40 .ports = &portFuzz,
41 };
42 struct AudioAdapter *adapter = nullptr;
43 ret = loadAdapterFuzzManager->LoadAdapter(loadAdapterFuzzManager, &descFuzz, &adapter);
44 if (ret == HDF_SUCCESS) {
45 result = true;
46 }
47 return result;
48 }
49 }
50 }
51
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)52 extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
53 {
54 OHOS::Audio::AudioLoadadapterDescFuzzTest(data, size);
55 return 0;
56 }