• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "dhcpclient_fuzzer.h"
17 #include "dhcp_client.h"
18 #include "dhcp_event.h"
19 
20 namespace OHOS {
21 namespace DHCP {
22     std::shared_ptr<DhcpClient> dhcpClient = DhcpClient::GetInstance(DHCP_CLIENT_ABILITY_ID);
23     static OHOS::sptr<DhcpClientCallBack> dhcpClientCallBack =
24         OHOS::sptr<DhcpClientCallBack>(new (std::nothrow)DhcpClientCallBack());
25     static OHOS::sptr<DhcpServerCallBack> dhcpServerCallBack =
26         OHOS::sptr<DhcpServerCallBack>(new (std::nothrow)DhcpServerCallBack());
DhcpClientFuzzerTest(const uint8_t * data,size_t size)27     bool DhcpClientFuzzerTest(const uint8_t* data, size_t size)
28     {
29         if (dhcpClient == nullptr) {
30             return false;
31         }
32 
33         RouterConfig config;
34         config.ifname = std::string(reinterpret_cast<const char*>(data), size);
35         config.bssid = std::string(reinterpret_cast<const char*>(data), size);
36         config.bIpv6 = false;
37         config.prohibitUseCacheIp = false;
38         dhcpClient->StartDhcpClient(config);
39         dhcpClient->StopDhcpClient(config.ifname, true, true);
40         dhcpClient->RegisterDhcpClientCallBack(config.ifname, dhcpClientCallBack);
41         IpCacheInfo ipCacheInfo;
42         ipCacheInfo.ssid = std::string(reinterpret_cast<const char*>(data), size);
43         ipCacheInfo.bssid = std::string(reinterpret_cast<const char*>(data), size);
44         dhcpClient->DealWifiDhcpCache(WIFI_DHCP_CACHE_ADD, ipCacheInfo);
45         dhcpClient->DealWifiDhcpCache(WIFI_DHCP_CACHE_REMOVE, ipCacheInfo);
46         return true;
47     }
48 }  // namespace DHCP
49 }  // namespace OHOS
50 
51 /* Fuzzer entry point */
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)52 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
53 {
54     OHOS::DHCP::DhcpClientFuzzerTest(data, size);
55     return 0;
56 }
57