mirror of
https://gitee.com/openharmony/communication_wifi.git
synced 2025-01-13 10:32:16 +00:00
新增wifi services scan模块fuzz测试
Signed-off-by: CodeAdo <baliguan163@163.com>
This commit is contained in:
parent
79640a3c1c
commit
f62303a3ec
@ -31,5 +31,6 @@ group("fuzztest") {
|
||||
"reassociate_fuzzer:ReAssociateFuzzTest",
|
||||
"reconnect_fuzzer:ReConnectFuzzTest",
|
||||
"wifip2pstub_fuzzer:WifiP2pStubFuzzTest",
|
||||
"wifiscanstub_fuzzer:WifiScanStubFuzzTest",
|
||||
]
|
||||
}
|
||||
|
57
wifi/test/fuzztest/wifi_sta/wifiscanstub_fuzzer/BUILD.gn
Normal file
57
wifi/test/fuzztest/wifi_sta/wifiscanstub_fuzzer/BUILD.gn
Normal file
@ -0,0 +1,57 @@
|
||||
# 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_sta"
|
||||
|
||||
##############################fuzztest##########################################
|
||||
ohos_fuzztest("WifiScanStubFuzzTest") {
|
||||
module_out_path = module_output_path
|
||||
fuzz_config_file = "$WIFI_ROOT_DIR/test/fuzztest/wifi_sta/wifiscanstub_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 = [ "wifiscanstub_fuzzer.cpp" ]
|
||||
|
||||
deps = [
|
||||
"$WIFI_ROOT_DIR/frameworks/native:wifi_sdk",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage:wifi_manager_service",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage:wifi_scan_ability",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage:wifi_scan_service_impl",
|
||||
"$WIFI_ROOT_DIR/utils:wifi_utils",
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
"c_utils:utils",
|
||||
"ipc:ipc_single",
|
||||
]
|
||||
|
||||
part_name = "wifi"
|
||||
subsystem_name = "communication"
|
||||
}
|
16
wifi/test/fuzztest/wifi_sta/wifiscanstub_fuzzer/corpus/init
Normal file
16
wifi/test/fuzztest/wifi_sta/wifiscanstub_fuzzer/corpus/init
Normal 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
|
25
wifi/test/fuzztest/wifi_sta/wifiscanstub_fuzzer/project.xml
Normal file
25
wifi/test/fuzztest/wifi_sta/wifiscanstub_fuzzer/project.xml
Normal 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>
|
@ -0,0 +1,192 @@
|
||||
/*
|
||||
* 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 "wifiscanstub_fuzzer.h"
|
||||
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
|
||||
#include "wifi_scan_stub.h"
|
||||
#include "message_parcel.h"
|
||||
#include "securec.h"
|
||||
#include "define.h"
|
||||
#include "wifi_log.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Wifi {
|
||||
constexpr size_t FOO_MAX_LEN = 1024;
|
||||
constexpr size_t U32_ZERO_SIZE = 0;
|
||||
const std::u16string FORMMGR_INTERFACE_TOKEN = u"ohos.wifi.IWifiScan";
|
||||
|
||||
class WifiScanStubTest : public WifiScanStub {
|
||||
public:
|
||||
WifiScanStubTest() = default;
|
||||
virtual ~WifiScanStubTest() = default;
|
||||
|
||||
ErrCode SetScanControlInfo(const ScanControlInfo &info) override
|
||||
{
|
||||
return WIFI_OPT_SUCCESS;
|
||||
}
|
||||
ErrCode Scan() override
|
||||
{
|
||||
return WIFI_OPT_SUCCESS;
|
||||
}
|
||||
ErrCode AdvanceScan(const WifiScanParams ¶ms) override
|
||||
{
|
||||
return WIFI_OPT_SUCCESS;
|
||||
}
|
||||
ErrCode IsWifiClosedScan(bool &bOpen) override
|
||||
{
|
||||
return WIFI_OPT_SUCCESS;
|
||||
}
|
||||
ErrCode GetScanInfoList(std::vector<WifiScanInfo> &result) override
|
||||
{
|
||||
return WIFI_OPT_SUCCESS;
|
||||
}
|
||||
ErrCode RegisterCallBack(const sptr<IWifiScanCallback> &callback, const std::vector<std::string> &event) override
|
||||
{
|
||||
return WIFI_OPT_SUCCESS;
|
||||
}
|
||||
ErrCode GetSupportedFeatures(long &features) override
|
||||
{
|
||||
return WIFI_OPT_SUCCESS;
|
||||
}
|
||||
bool IsRemoteDied(void) override
|
||||
{
|
||||
return WIFI_OPT_SUCCESS;
|
||||
}
|
||||
};
|
||||
|
||||
std::shared_ptr<WifiScanStub> pWifiScanStub = std::make_shared<WifiScanStubTest>();
|
||||
void RemoteRequestSetScanControlInfo(const char* data, size_t size) // 1 WIFI_SVR_CMD_SET_SCAN_CONTROL_INFO
|
||||
{
|
||||
MessageParcel datas;
|
||||
datas.WriteInterfaceToken(FORMMGR_INTERFACE_TOKEN);
|
||||
datas.WriteInt32(0);
|
||||
datas.WriteBuffer(data, size);
|
||||
datas.RewindRead(0);
|
||||
MessageParcel reply;
|
||||
MessageOption option;
|
||||
int result = pWifiScanStub->OnRemoteRequest(WIFI_SVR_CMD_SET_SCAN_CONTROL_INFO, datas, reply, option);
|
||||
LOGI("wifiscanstub_fuzzer OnRemoteRequest(0x%{public}x %{public}d)", WIFI_SVR_CMD_SET_SCAN_CONTROL_INFO, result);
|
||||
}
|
||||
|
||||
void RemoteRequestFullScan(const char* data, size_t size) // 2 WIFI_SVR_CMD_FULL_SCAN
|
||||
{
|
||||
MessageParcel datas;
|
||||
datas.WriteInterfaceToken(FORMMGR_INTERFACE_TOKEN);
|
||||
datas.WriteInt32(0);
|
||||
datas.WriteBuffer(data, size);
|
||||
datas.RewindRead(0);
|
||||
MessageParcel reply;
|
||||
MessageOption option;
|
||||
int result = pWifiScanStub->OnRemoteRequest(WIFI_SVR_CMD_FULL_SCAN, datas, reply, option);
|
||||
LOGI("wifiscanstub_fuzzer OnRemoteRequest(0x%{public}x %{public}d)", WIFI_SVR_CMD_FULL_SCAN, result);
|
||||
}
|
||||
|
||||
void RemoteRequestSpecifiedParamsScan(const char* data, size_t size) // 3 WIFI_SVR_CMD_SPECIFIED_PARAMS_SCAN
|
||||
{
|
||||
MessageParcel datas;
|
||||
datas.WriteInterfaceToken(FORMMGR_INTERFACE_TOKEN);
|
||||
datas.WriteInt32(0);
|
||||
datas.WriteBuffer(data, size);
|
||||
datas.RewindRead(0);
|
||||
MessageParcel reply;
|
||||
MessageOption option;
|
||||
int result = pWifiScanStub->OnRemoteRequest(WIFI_SVR_CMD_SPECIFIED_PARAMS_SCAN, datas, reply, option);
|
||||
LOGI("wifiscanstub_fuzzer OnRemoteRequest(0x%{public}x %{public}d)", WIFI_SVR_CMD_SPECIFIED_PARAMS_SCAN, result);
|
||||
}
|
||||
|
||||
void RemoteRequestIsScanAlwaysActive(const char* data, size_t size) // 4 WIFI_SVR_CMD_IS_SCAN_ALWAYS_ACTIVE
|
||||
{
|
||||
MessageParcel datas;
|
||||
datas.WriteInterfaceToken(FORMMGR_INTERFACE_TOKEN);
|
||||
datas.WriteInt32(0);
|
||||
datas.WriteBuffer(data, size);
|
||||
datas.RewindRead(0);
|
||||
MessageParcel reply;
|
||||
MessageOption option;
|
||||
int result = pWifiScanStub->OnRemoteRequest(WIFI_SVR_CMD_IS_SCAN_ALWAYS_ACTIVE, datas, reply, option);
|
||||
LOGI("wifiscanstub_fuzzer OnRemoteRequest(0x%{public}x %{public}d)", WIFI_SVR_CMD_IS_SCAN_ALWAYS_ACTIVE, result);
|
||||
}
|
||||
|
||||
void RemoteRequestGetScanInfoList(const char* data, size_t size) // 5 WIFI_SVR_CMD_GET_SCAN_INFO_LIST
|
||||
{
|
||||
MessageParcel datas;
|
||||
datas.WriteInterfaceToken(FORMMGR_INTERFACE_TOKEN);
|
||||
datas.WriteInt32(0);
|
||||
datas.WriteBuffer(data, size);
|
||||
datas.RewindRead(0);
|
||||
MessageParcel reply;
|
||||
MessageOption option;
|
||||
int result = pWifiScanStub->OnRemoteRequest(WIFI_SVR_CMD_GET_SCAN_INFO_LIST, datas, reply, option);
|
||||
LOGI("wifiscanstub_fuzzer OnRemoteRequest(0x%{public}x %{public}d)", WIFI_SVR_CMD_GET_SCAN_INFO_LIST, result);
|
||||
}
|
||||
|
||||
void RemoteRequestRegisterCallBack(const char* data, size_t size) // 6 WIFI_SVR_CMD_REGISTER_SCAN_CALLBACK
|
||||
{
|
||||
MessageParcel datas;
|
||||
datas.WriteInterfaceToken(FORMMGR_INTERFACE_TOKEN);
|
||||
datas.WriteInt32(0);
|
||||
datas.WriteBuffer(data, size);
|
||||
datas.RewindRead(0);
|
||||
MessageParcel reply;
|
||||
MessageOption option;
|
||||
int result = pWifiScanStub->OnRemoteRequest(WIFI_SVR_CMD_REGISTER_SCAN_CALLBACK, datas, reply, option);
|
||||
LOGI("wifiscanstub_fuzzer OnRemoteRequest(0x%{public}x %{public}d)", WIFI_SVR_CMD_REGISTER_SCAN_CALLBACK, result);
|
||||
}
|
||||
|
||||
void RemoteRequestGetSupportedFeatures(const char* data, size_t size) // 7 WIFI_SVR_CMD_GET_SUPPORTED_FEATURES
|
||||
{
|
||||
MessageParcel datas;
|
||||
datas.WriteInterfaceToken(FORMMGR_INTERFACE_TOKEN);
|
||||
datas.WriteInt32(0);
|
||||
datas.WriteBuffer(data, size);
|
||||
datas.RewindRead(0);
|
||||
MessageParcel reply;
|
||||
MessageOption option;
|
||||
int result = pWifiScanStub->OnRemoteRequest(WIFI_SVR_CMD_GET_SUPPORTED_FEATURES, datas, reply, option);
|
||||
LOGI("wifiscanstub_fuzzer OnRemoteRequest(0x%{public}x %{public}d)", WIFI_SVR_CMD_GET_SUPPORTED_FEATURES, result);
|
||||
}
|
||||
|
||||
bool DoSomethingInterestingWithMyAPI(const char* data, size_t size)
|
||||
{
|
||||
RemoteRequestSetScanControlInfo(data, size);
|
||||
RemoteRequestFullScan(data, size);
|
||||
RemoteRequestSpecifiedParamsScan(data, size);
|
||||
RemoteRequestIsScanAlwaysActive(data, size);
|
||||
RemoteRequestGetScanInfoList(data, size);
|
||||
RemoteRequestRegisterCallBack(data, size);
|
||||
RemoteRequestGetSupportedFeatures(data, size);
|
||||
return true;
|
||||
}
|
||||
|
||||
/* Fuzzer entry point */
|
||||
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
|
||||
{
|
||||
if (data == nullptr) {
|
||||
LOGE("LLVMFuzzerTestOneInput data is null, size:%{public}zu", size);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (size <= U32_ZERO_SIZE || size > OHOS::Wifi::FOO_MAX_LEN) {
|
||||
LOGE("LLVMFuzzerTestOneInput size invalid parameter, size:%{public}zu", size);
|
||||
return 0;
|
||||
}
|
||||
OHOS::Wifi::DoSomethingInterestingWithMyAPI((const char*)data, size);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
@ -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_SCAN_STUB_H
|
||||
#define WIFI_FUZZ_SCAN_STUB_H
|
||||
|
||||
#define FUZZ_PROJECT_NAME "wifiscanstub_fuzzer"
|
||||
|
||||
#endif
|
Loading…
x
Reference in New Issue
Block a user