• 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 "audiointerfaceliboutputrendercmdid_fuzzer.h"
17 #include "audio_adm_fuzzer_common.h"
18 
19 namespace OHOS {
20 namespace Audio {
AudioInterfaceliboutputrenderCmdidFuzzTest(const uint8_t * data,size_t size)21     bool AudioInterfaceliboutputrenderCmdidFuzzTest(const uint8_t *data, size_t size)
22     {
23         bool result = false;
24         char resolvedPath[] = HDF_LIBRARY_FULL_PATH("libaudio_render_adapter");
25         void *outputRenFuzzPtrHandle = dlopen(resolvedPath, RTLD_LAZY);
26         if (outputRenFuzzPtrHandle == nullptr) {
27             HDF_LOGE("%{public}s: dlopen failed \n", __func__);
28             return false;
29         }
30         struct DevHandle *(*BindServiceRender)(const char *) = nullptr;
31         int32_t (*InterfaceLibOutputRender)(struct DevHandle *, int, struct AudioHwRenderParam *) = nullptr;
32         BindServiceRender = reinterpret_cast<struct DevHandle* (*)(const char *)>
33             (dlsym(outputRenFuzzPtrHandle, "AudioBindServiceRender"));
34         if (BindServiceRender == nullptr) {
35             HDF_LOGE("%{public}s: dlsym AudioBindServiceRender failed \n", __func__);
36             dlclose(outputRenFuzzPtrHandle);
37             return false;
38         }
39         struct DevHandle *handle = nullptr;
40         handle = BindServiceRender(BIND_CONTROL.c_str());
41         if (handle == nullptr) {
42             HDF_LOGE("%{public}s: BindServiceRender failed \n", __func__);
43             dlclose(outputRenFuzzPtrHandle);
44             return false;
45         }
46         InterfaceLibOutputRender = reinterpret_cast<int32_t (*)(struct DevHandle *, int,
47             struct AudioHwRenderParam *)>(dlsym(outputRenFuzzPtrHandle, "AudioInterfaceLibOutputRender"));
48         if (InterfaceLibOutputRender == nullptr) {
49             HDF_LOGE("%{public}s: dlsym AudioInterfaceLibOutputRender failed \n", __func__);
50             dlclose(outputRenFuzzPtrHandle);
51             return false;
52         }
53         struct AudioHwRender *hwRender = nullptr;
54         int32_t ret = BindServiceAndHwRender(hwRender);
55         if (size < sizeof(int32_t)) {
56             return false;
57         }
58         int32_t cmdId = *(reinterpret_cast<int32_t *>(const_cast<uint8_t *>(data)));
59         InterfaceLibOutputRender(handle, cmdId, &hwRender->renderParam);
60         if (ret == HDF_SUCCESS) {
61             result = true;
62         }
63         free(hwRender);
64         void (*CloseService)(const struct DevHandle *) = nullptr;
65         CloseService = reinterpret_cast<void (*)(const struct DevHandle *)>(dlsym(outputRenFuzzPtrHandle,
66             "AudioCloseServiceRender"));
67         if (CloseService == nullptr) {
68             HDF_LOGE("%{public}s: dlsym AudioCloseServiceRender failed \n", __func__);
69             dlclose(outputRenFuzzPtrHandle);
70             return false;
71         }
72         CloseService(handle);
73         dlclose(outputRenFuzzPtrHandle);
74         return result;
75     }
76 }
77 }
78 
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)79 extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
80 {
81     OHOS::Audio::AudioInterfaceliboutputrenderCmdidFuzzTest(data, size);
82     return 0;
83 }