• 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 "codecgetcomponentcapabilitylist_fuzzer.h"
17 #include "codec_callback_type_stub.h"
18 #include "codec_component_type.h"
19 #include "codec_component_manager.h"
20 
21 #include <osal_mem.h>
22 #include <hdf_log.h>
23 
24 namespace OHOS {
25 namespace Codec {
CodecGetComponentCapabilityList(const uint8_t * data,size_t size)26     bool CodecGetComponentCapabilityList(const uint8_t* data, size_t size)
27     {
28         bool result = false;
29         struct CodecComponentManager *manager = nullptr;
30 
31         manager = GetCodecComponentManager();
32         if (manager == nullptr) {
33             HDF_LOGE("%{public}s: GetCodecComponentManager failed\n", __func__);
34             return false;
35         }
36 
37         CodecCompCapability *capList = (CodecCompCapability *)OsalMemAlloc(sizeof(CodecCompCapability)
38             *reinterpret_cast<int64_t>(data));
39         if (capList == NULL) {
40             HDF_LOGE("%{public}s: OsalMemAlloc CodecCompCapability failed\n", __func__);
41             return false;
42         }
43 
44         int32_t ret = manager->GetComponentCapabilityList(capList, *(int32_t *)data);
45         if (ret == HDF_SUCCESS) {
46             HDF_LOGI("%{public}s: GetComponentCapabilityList succeed\n", __func__);
47             result = true;
48         }
49         OsalMemFree(capList);
50         CodecComponentManagerRelease();
51 
52         return result;
53     }
54 } // namespace codec
55 } // namespace OHOS
56 
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)57 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
58 {
59     OHOS::Codec::CodecGetComponentCapabilityList(data, size);
60     return 0;
61 }