• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 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 "audio_adm_fuzzer_common.h"
17 
18 using namespace HMOS::Audio;
19 
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)20 extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
21 {
22     char resolvedPath[] = HDF_LIBRARY_FULL_PATH("libhdi_audio_interface_lib_render");
23     void *PtrHandle = dlopen(resolvedPath, RTLD_LAZY);
24     if (PtrHandle == nullptr) {
25         return HDF_FAILURE;
26     }
27     struct DevHandle *(*BindServiceRender)(const char *) = nullptr;
28     int32_t (*InterfaceLibOutputRender)(struct DevHandle *, int, struct AudioHwRenderParam *) = nullptr;
29     BindServiceRender = (struct DevHandle* (*)(const char *))dlsym(PtrHandle, "AudioBindServiceRender");
30     if (BindServiceRender == nullptr) {
31         dlclose(PtrHandle);
32         return HDF_FAILURE;
33     }
34     struct DevHandle *handle = nullptr;
35     handle = BindServiceRender(BIND_CONTROL.c_str());
36     if (handle == nullptr) {
37         dlclose(PtrHandle);
38         return HDF_FAILURE;
39     }
40     InterfaceLibOutputRender = (int32_t (*)(struct DevHandle *, int,
41         struct AudioHwRenderParam *))dlsym(PtrHandle, "AudioInterfaceLibOutputRender");
42     if (InterfaceLibOutputRender == nullptr) {
43         dlclose(PtrHandle);
44         return HDF_FAILURE;
45     }
46     struct AudioHwRender *hwRender = nullptr;
47     int32_t ret = BindServiceAndHwRender(hwRender);
48     InterfaceLibOutputRender(handle, size, &hwRender->renderParam);
49     free(hwRender);
50     void (*CloseService)(const struct DevHandle *) = nullptr;
51     CloseService = (void (*)(const struct DevHandle *))dlsym(PtrHandle, "AudioCloseServiceRender");
52     if (CloseService == nullptr) {
53         dlclose(PtrHandle);
54         return HDF_FAILURE;
55     }
56     CloseService(handle);
57     dlclose(PtrHandle);
58     return ret;
59 }
60