新增Fuzz接口

Signed-off-by: sunjingqiang <17319862417@163.com>
This commit is contained in:
sunjingqiang 2023-06-14 18:11:30 +08:00
parent cab18355ff
commit 58c637e132
7 changed files with 441 additions and 0 deletions

View File

@ -103,6 +103,7 @@
}
],
"test": [
"//foundation/communication/wifi/wifi/test/fuzztest/wifi_manage:fuzztest",
"//foundation/communication/wifi/wifi/test/fuzztest/wifi_sta:fuzztest",
"//foundation/communication/wifi/wifi/test/wifi_standard/wifi_framework/wifi_manage/wifi_scan:unittest",
"//foundation/communication/wifi/wifi/test/wifi_standard/wifi_framework/wifi_manage/wifi_sta:unittest",

View File

@ -0,0 +1,22 @@
# Copyright (C) 2022 Huawei Device Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import("//build/test.gni")
group("fuzztest") {
testonly = true
deps = []
deps += [
"wifip2pstub_fuzzer:WifiP2pStubFuzzTest",
]
}

View File

@ -0,0 +1,59 @@
# Copyright (C) 2022 Huawei Device Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#####################hydra-fuzz###################
import("//build/config/features.gni")
import("//build/test.gni")
import("//foundation/communication/wifi/wifi/wifi.gni")
module_output_path = "wifi/wifi_manage"
##############################fuzztest##########################################
ohos_fuzztest("WifiP2pStubFuzzTest") {
module_out_path = module_output_path
fuzz_config_file = "$WIFI_ROOT_DIR/test/fuzztest/wifi_manage/wifip2pstub_fuzzer"
include_dirs = [
"$WIFI_ROOT_DIR/interfaces/inner_api",
"$WIFI_ROOT_DIR/frameworks/native/include",
"$WIFI_ROOT_DIR/frameworks/native/interfaces",
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage",
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_toolkit/net_helper",
"$WIFI_ROOT_DIR/test/fuzztest/fuzz_common_func",
]
cflags = [
"-g",
"-O0",
"-Wno-unused-variable",
"-fno-omit-frame-pointer",
]
sources = [ "wifip2pstub_fuzzer.cpp" ]
deps = [
"$WIFI_ROOT_DIR/frameworks/native:wifi_sdk",
"$WIFI_ROOT_DIR/service/wifi_standard/wifi_manage:wifi_manager_service",
"$WIFI_ROOT_DIR/service/wifi_standard/wifi_manage/wifi_scan:wifi_scan_service",
"$WIFI_ROOT_DIR/service/wifi_standard/wifi_manage:wifi_p2p_ability",
"$WIFI_ROOT_DIR/service/wifi_standard/wifi_manage:wifi_p2p_servce_impl",
"$WIFI_ROOT_DIR/service/wifi_standard/wifi_toolkit:wifi_toolkit",
"$WIFI_ROOT_DIR/utils:wifi_utils,
]
external_deps = [
"c_utils:utils",
"ipc:ipc_single",
]
part_name = "wifi"
subsystem_name = "communication"
}

View File

@ -0,0 +1,16 @@
/*
* Copyright (C) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
FUZZ

View File

@ -0,0 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2022 Huawei Device Co., Ltd.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<fuzz_config>
<fuzztest>
<!-- maximum length of a test input -->
<max_len>1000</max_len>
<!-- maximum total time in seconds to run the fuzzer -->
<max_total_time>300</max_total_time>
<!-- memory usage limit in Mb -->
<rss_limit_mb>4096</rss_limit_mb>
</fuzztest>
</fuzz_config>

View File

@ -0,0 +1,297 @@
/*
* Copyright (c) 2023 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "wifip2pstub_fuzzer.h"
#include <cstddef>
#include <cstdint>
#include "wifi_p2p_stub.h"
#include "message_parcel.h"
#include "securec.h"
#include "define.h"
namespace OHOS {
namespace Wifi {
constexpr size_t FOO_MAX_LEN = 1024;
constexpr size_t U32_AT_SIZE = 4;
const std::u16string FORMMGR_INTERFACE_TOKEN = u"ohos.wifi.IWifi.IWifiP2pService";
std::shared_ptr<WifiP2pStub> pWifiP2pStub = std::make_shared<WifiP2pStubTest>();
class WifiP2pStubTest : public WifiP2pStub {
public:
WifiP2pStubTest() = default;
virtual ~WifiP2pStubTest() = default;
ErrCode MonitorCfgChange() override
{
return WIFI_OPT_SUCCESS;
}
ErrCode EnableP2p() override
{
return WIFI_OPT_SUCCESS;
}
ErrCode DisableP2p() override
{
return WIFI_OPT_SUCCESS;
}
ErrCode DiscoverDevices() override
{
return WIFI_OPT_SUCCESS;
}
ErrCode StopDiscoverDevices() override
{
return WIFI_OPT_SUCCESS;
}
ErrCode DiscoverServices() override
{
return WIFI_OPT_SUCCESS;
}
ErrCode StopDiscoverServices() override
{
return WIFI_OPT_SUCCESS;
}
ErrCode RequestService(const WifiP2pDevice &device, const WifiP2pServiceRequest &request) override
{
return WIFI_OPT_SUCCESS;
}
ErrCode PutLocalP2pService(const WifiP2pServiceInfo &srvInfo) override
{
return WIFI_OPT_SUCCESS;
}
ErrCode DeleteLocalP2pService(const WifiP2pServiceInfo &srvInfo) override
{
return WIFI_OPT_SUCCESS;
}
ErrCode StartP2pListen(int period, int interval) override
{
return WIFI_OPT_SUCCESS;
}
ErrCode StopP2pListen() override
{
return WIFI_OPT_SUCCESS;
}
ErrCode CreateGroup(const WifiP2pConfig &config) override
{
return WIFI_OPT_SUCCESS;
}
ErrCode RemoveGroup() override
{
return WIFI_OPT_SUCCESS;
}
ErrCode DeleteGroup(const WifiP2pGroupInfo &group) override
{
return WIFI_OPT_SUCCESS;
}
ErrCode P2pConnect(const WifiP2pConfig &config) override
{
return WIFI_OPT_SUCCESS;
}
ErrCode P2pCancelConnect() override
{
return WIFI_OPT_SUCCESS;
}
ErrCode QueryP2pLinkedInfo(WifiP2pLinkedInfo& linkedInfo) override
{
return WIFI_OPT_SUCCESS;
}
ErrCode GetCurrentGroup(WifiP2pGroupInfo &group) override
{
return WIFI_OPT_SUCCESS;
}
ErrCode GetP2pEnableStatus(int &status) override
{
return WIFI_OPT_SUCCESS;
}
ErrCode GetP2pDiscoverStatus(int &status) override
{
return WIFI_OPT_SUCCESS;
}
ErrCode GetP2pDiscoverStatus(int &status) override
{
return WIFI_OPT_SUCCESS;
}
ErrCode QueryP2pDevices(std::vector<WifiP2pDevice> &devices) override
{
return WIFI_OPT_SUCCESS;
}
ErrCode QueryP2pLocalDevice(WifiP2pDevice &device) override
{
return WIFI_OPT_SUCCESS;
}
ErrCode QueryP2pGroups(std::vector<WifiP2pGroupInfo> &groups) override
{
return WIFI_OPT_SUCCESS;
}
ErrCode QueryP2pServices(std::vector<WifiP2pServiceInfo> &services) override
{
return WIFI_OPT_SUCCESS;
}
ErrCode RegisterCallBack(const sptr<IWifiP2pCallback> &callback, const std::vector<std::string> &event) override
{
return WIFI_OPT_SUCCESS;
}
ErrCode GetSupportedFeatures(long &features) override
{
return WIFI_OPT_SUCCESS;
}
ErrCode SetP2pDeviceName(const std::string &deviceName) override
{
return WIFI_OPT_SUCCESS;
}
ErrCode SetP2pWfdInfo(const WifiP2pWfdInfo &wfdInfo) override
{
return WIFI_OPT_SUCCESS;
}
ErrCode Hid2dRequestGcIp(const std::string& gcMac, std::string& ipAddr) override
{
return WIFI_OPT_SUCCESS;
}
ErrCode Hid2dSharedlinkIncrease() override
{
return WIFI_OPT_SUCCESS;
}
ErrCode Hid2dSharedlinkDecrease() override
{
return WIFI_OPT_SUCCESS;
}
ErrCode Hid2dCreateGroup(const int frequency, FreqType type) override
{
return WIFI_OPT_SUCCESS;
}
ErrCode Hid2dConnect(const Hid2dConnectConfig& config) override
{
return WIFI_OPT_SUCCESS;
}
ErrCode Hid2dConfigIPAddr(const std::string& ifName, const IpAddrInfo& ipInfo) override
{
return WIFI_OPT_SUCCESS;
}
ErrCode Hid2dReleaseIPAddr(const std::string& ifName) override
{
return WIFI_OPT_SUCCESS;
}
ErrCode Hid2dGetRecommendChannel(const RecommendChannelRequest& request,
RecommendChannelResponse& response) override
{
return WIFI_OPT_SUCCESS;
}
ErrCode Hid2dGetChannelListFor5G(std::vector<int>& vecChannelList) override
{
return WIFI_OPT_SUCCESS;
}
ErrCode Hid2dGetSelfWifiCfgInfo(SelfCfgType cfgType,
char cfgData[CFG_DATA_MAX_BYTES], int* getDatValidLen) override
{
return WIFI_OPT_SUCCESS;
}
ErrCode Hid2dSetPeerWifiCfgInfo(PeerCfgType cfgType,
char cfgData[CFG_DATA_MAX_BYTES], int setDataValidLen) override
{
return WIFI_OPT_SUCCESS;
}
ErrCode Hid2dSetUpperScene(const std::string& ifName, const Hid2dUpperScene& scene) override
{
return WIFI_OPT_SUCCESS;
}
bool IsRemoteDied() override
{
return WIFI_OPT_SUCCESS;
}
};
void OnEnableP2pTest(const char* data, size_t size)
{
MessageParcel datas;
datas.WriteInterfaceToken(FORMMGR_INTERFACE_TOKEN);
datas.WriteBuffer(data, size);
datas.RewindRead(0);
MessageParcel reply;
MessageOption option;
pWifiP2pStub->OnRemoteRequest(WIFI_SVR_CMD_P2P_ENABLE, datas, reply, option);
}
bool DoSomethingInterestingWithMyAPI(const char* data, size_t size)
{
OnEnableP2pTest();
return true;
}
};
};
/* Fuzzer entry point */
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
{
/* Run your code on data */
if (data == nullptr) {
return 0;
}
if (size < OHOS::Wifi::U32_AT_SIZE) {
return 0;
}
/* Validate the length of size */
if (size == 0 || size > OHOS::Wifi::FOO_MAX_LEN) {
return 0;
}
OHOS::Wifi::DoSomethingInterestingWithMyAPI(ch, size);
return 0;
}

View File

@ -0,0 +1,21 @@
/*
* Copyright (C) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef WIFI_FUZZ_P2P_STUB_H
#define WIFI_FUZZ_P2P_STUB_H
#define FUZZ_PROJECT_NAME "wifip2pstub_fuzzer"
#endif