1 /*
2 * Copyright (c) 2022-2023 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 "codeccomponenttunnelrequest_fuzzer.h"
17 #include "codeccommon_fuzzer.h"
18
19 #include <securec.h>
20
21 namespace {
22 struct AllParameters {
23 uint32_t port;
24 int32_t tunneledComp;
25 uint32_t tunneledPort;
26 struct OMX_TUNNELSETUPTYPE *tunnelSetup;
27 };
28 }
29
30 namespace OHOS {
31 namespace Codec {
CodecComponentTunnelRequest(const uint8_t * data,size_t size)32 bool CodecComponentTunnelRequest(const uint8_t *data, size_t size)
33 {
34 struct AllParameters params;
35 if (data == nullptr) {
36 return false;
37 }
38
39 uint8_t *rawData = const_cast<uint8_t *>(data);
40 if (size > sizeof(uint32_t) + sizeof(int32_t) + sizeof(uint32_t) + sizeof(OMX_TUNNELSETUPTYPE *)) {
41 params.port = Convert2Uint32(rawData);
42 rawData = rawData + sizeof(uint32_t);
43 params.tunneledComp = static_cast<int32_t>(Convert2Uint32(rawData));
44 rawData = rawData + sizeof(int32_t);
45 params.tunneledPort = Convert2Uint32(rawData);
46 rawData = rawData + sizeof(uint32_t);
47 params.tunnelSetup = reinterpret_cast<OMX_TUNNELSETUPTYPE *>(rawData);
48 } else {
49 params.tunneledComp = static_cast<int32_t>(Convert2Uint32(rawData));
50 params.port = Convert2Uint32(rawData);
51 params.tunneledPort = Convert2Uint32(rawData);
52 params.tunnelSetup = reinterpret_cast<OMX_TUNNELSETUPTYPE *>(rawData);
53 }
54
55 bool result = Preconditions();
56 if (!result) {
57 HDF_LOGE("%{public}s: Preconditions failed\n", __func__);
58 return false;
59 }
60
61 int32_t ret = g_component->ComponentTunnelRequest(g_component, params.port, params.tunneledComp,
62 params.tunneledPort, params.tunnelSetup);
63 if (ret != HDF_SUCCESS) {
64 HDF_LOGE("%{public}s: ComponentTunnelRequest failed, ret is [%{public}x]\n", __func__, ret);
65 }
66
67 result = Destroy();
68 if (!result) {
69 HDF_LOGE("%{public}s: Destroy failed\n", __func__);
70 return false;
71 }
72
73 return true;
74 }
75 } // namespace codec
76 } // namespace OHOS
77
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)78 extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
79 {
80 OHOS::Codec::CodecComponentTunnelRequest(data, size);
81 return 0;
82 }