1 /*
2 * Copyright (C) 2024 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 "dhcpclientcbkstub_fuzzer.h"
17 #include "dhcp_client.h"
18 #include "dhcp_event.h"
19 #include "dhcp_manager_service_ipc_interface_code.h"
20 #include "dhcp_client_callback_stub.h"
21 #include "dhcp_fuzz_common_func.h"
22
23 namespace OHOS {
24 namespace DHCP {
25 constexpr size_t U32_AT_SIZE_ZERO = 4;
26 constexpr size_t MAP_SCAN_NUMS = 4;
27 const std::u16string FORMMGR_INTERFACE_TOKEN = u"ohos.wifi.IDhcpClientCallBack";
28 std::shared_ptr<DhcpClientCallBackStub> pDhcpClientCbkStub = std::make_shared<DhcpClientCallBackStub>();
29
OnGetSupportedFeaturesTest(const uint8_t * data,size_t size)30 void OnGetSupportedFeaturesTest(const uint8_t* data, size_t size)
31 {
32 uint32_t code = U32_AT(data) % MAP_SCAN_NUMS + static_cast<uint32_t>
33 (DhcpClientInterfaceCode::DHCP_CLIENT_CBK_CMD_IP_SUCCESS_CHANGE);
34 MessageParcel datas;
35 datas.WriteInterfaceToken(FORMMGR_INTERFACE_TOKEN);
36 datas.WriteInt32(0);
37 datas.WriteBuffer(data, size);
38 datas.RewindRead(0);
39 MessageParcel reply;
40 MessageOption option;
41 pDhcpClientCbkStub->OnRemoteRequest(code, datas, reply, option);
42 }
43
44 /* Fuzzer entry point */
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)45 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
46 {
47 if ((data == nullptr) || (size <= OHOS::DHCP::U32_AT_SIZE_ZERO)) {
48 return 0;
49 }
50 OHOS::DHCP::OnGetSupportedFeaturesTest(data, size);
51 return 0;
52 }
53 } // namespace DHCP
54 } // namespace OHOS
55
56