• 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 "audiocapturereqmmapbufferdesc_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 {
AudioCaptureReqmmapbufferDescFuzzTest(const uint8_t * data,size_t size)23     bool AudioCaptureReqmmapbufferDescFuzzTest(const uint8_t *data, size_t size)
24     {
25         bool result = false;
26         TestAudioManager *reqMmapFuzzManager = nullptr;
27         struct AudioAdapter *reqMmapFuzzAdapter = nullptr;
28         struct AudioCapture *reqMmapFuzzCapture = nullptr;
29         int32_t ret = AudioGetManagerCreateStartCapture(reqMmapFuzzManager, &reqMmapFuzzAdapter, &reqMmapFuzzCapture);
30         if (ret < 0 || reqMmapFuzzAdapter == nullptr ||
31             reqMmapFuzzCapture == nullptr || reqMmapFuzzManager == nullptr) {
32             HDF_LOGE("%{public}s: AudioGetManagerCreateStartCapture failed \n", __func__);
33             return false;
34         }
35 
36         struct AudioMmapBufferDescripter descFuzz = {};
37         int32_t copySize = sizeof(descFuzz) > size ? size : sizeof(descFuzz);
38         if (memcpy_s((void *)&descFuzz, sizeof(descFuzz), data, copySize) != 0) {
39             return false;
40         }
41         ret = reqMmapFuzzCapture->attr.ReqMmapBuffer((AudioHandle)reqMmapFuzzCapture, size, &descFuzz);
42         if (ret == HDF_SUCCESS) {
43             (void)munmap(descFuzz.memoryAddress, size);
44             result = true;
45         }
46         reqMmapFuzzAdapter->DestroyCapture(reqMmapFuzzAdapter, reqMmapFuzzCapture);
47         reqMmapFuzzManager->UnloadAdapter(reqMmapFuzzManager, reqMmapFuzzAdapter);
48         return result;
49     }
50 }
51 }
52 
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)53 extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
54 {
55     OHOS::Audio::AudioCaptureReqmmapbufferDescFuzzTest(data, size);
56     return 0;
57 }