1518678f8Sopenharmony_ci/* 2518678f8Sopenharmony_ci * Copyright (C) 2024 Huawei Device Co., Ltd. 3518678f8Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4518678f8Sopenharmony_ci * you may not use this file except in compliance with the License. 5518678f8Sopenharmony_ci * You may obtain a copy of the License at 6518678f8Sopenharmony_ci * 7518678f8Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8518678f8Sopenharmony_ci * 9518678f8Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 10518678f8Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 11518678f8Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12518678f8Sopenharmony_ci * See the License for the specific language governing permissions and 13518678f8Sopenharmony_ci * limitations under the License. 14518678f8Sopenharmony_ci */ 15518678f8Sopenharmony_ci 16518678f8Sopenharmony_ci#include "dhcpclientcbkstub_fuzzer.h" 17518678f8Sopenharmony_ci#include "dhcp_client.h" 18518678f8Sopenharmony_ci#include "dhcp_event.h" 19518678f8Sopenharmony_ci#include "dhcp_manager_service_ipc_interface_code.h" 20518678f8Sopenharmony_ci#include "dhcp_client_callback_stub.h" 21518678f8Sopenharmony_ci#include "dhcp_fuzz_common_func.h" 22518678f8Sopenharmony_ci 23518678f8Sopenharmony_cinamespace OHOS { 24518678f8Sopenharmony_cinamespace DHCP { 25518678f8Sopenharmony_ciconstexpr size_t U32_AT_SIZE_ZERO = 4; 26518678f8Sopenharmony_ciconstexpr size_t MAP_SCAN_NUMS = 4; 27518678f8Sopenharmony_ciconst std::u16string FORMMGR_INTERFACE_TOKEN = u"ohos.wifi.IDhcpClientCallBack"; 28518678f8Sopenharmony_cistd::shared_ptr<DhcpClientCallBackStub> pDhcpClientCbkStub = std::make_shared<DhcpClientCallBackStub>(); 29518678f8Sopenharmony_ci 30518678f8Sopenharmony_civoid OnGetSupportedFeaturesTest(const uint8_t* data, size_t size) 31518678f8Sopenharmony_ci{ 32518678f8Sopenharmony_ci uint32_t code = U32_AT(data) % MAP_SCAN_NUMS + static_cast<uint32_t> 33518678f8Sopenharmony_ci (DhcpClientInterfaceCode::DHCP_CLIENT_CBK_CMD_IP_SUCCESS_CHANGE); 34518678f8Sopenharmony_ci MessageParcel datas; 35518678f8Sopenharmony_ci datas.WriteInterfaceToken(FORMMGR_INTERFACE_TOKEN); 36518678f8Sopenharmony_ci datas.WriteInt32(0); 37518678f8Sopenharmony_ci datas.WriteBuffer(data, size); 38518678f8Sopenharmony_ci datas.RewindRead(0); 39518678f8Sopenharmony_ci MessageParcel reply; 40518678f8Sopenharmony_ci MessageOption option; 41518678f8Sopenharmony_ci pDhcpClientCbkStub->OnRemoteRequest(code, datas, reply, option); 42518678f8Sopenharmony_ci} 43518678f8Sopenharmony_ci 44518678f8Sopenharmony_ci/* Fuzzer entry point */ 45518678f8Sopenharmony_ciextern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) 46518678f8Sopenharmony_ci{ 47518678f8Sopenharmony_ci if ((data == nullptr) || (size <= OHOS::DHCP::U32_AT_SIZE_ZERO)) { 48518678f8Sopenharmony_ci return 0; 49518678f8Sopenharmony_ci } 50518678f8Sopenharmony_ci OHOS::DHCP::OnGetSupportedFeaturesTest(data, size); 51518678f8Sopenharmony_ci return 0; 52518678f8Sopenharmony_ci} 53518678f8Sopenharmony_ci} // namespace DHCP 54518678f8Sopenharmony_ci} // namespace OHOS 55518678f8Sopenharmony_ci 56