• 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 (*InterfaceLibCtlRender)(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     InterfaceLibCtlRender = (int32_t (*)(struct DevHandle *, int,
41         struct AudioHwRenderParam *))dlsym(PtrHandle, "AudioInterfaceLibCtlRender");
42     if (InterfaceLibCtlRender == nullptr) {
43         dlclose(PtrHandle);
44         return HDF_FAILURE;
45     }
46     struct AudioHwRender *hwRender = nullptr;
47     int32_t ret = BindServiceAndHwRender(hwRender);
48     hwRender->renderParam.renderMode.hwInfo.card = AUDIO_SERVICE_IN;
49     InterfaceLibCtlRender(handle, size, &hwRender->renderParam);
50     free(hwRender);
51     void (*CloseService)(const struct DevHandle *) = nullptr;
52     CloseService = (void (*)(const struct DevHandle *))dlsym(PtrHandle, "AudioCloseServiceRender");
53     if (CloseService == nullptr) {
54         dlclose(PtrHandle);
55         return HDF_FAILURE;
56     }
57     CloseService(handle);
58     dlclose(PtrHandle);
59     return ret;
60 }
61