wifi fuzz用例修复

Signed-off-by: CodeAdo <baliguan163@163.com>
This commit is contained in:
CodeAdo 2023-08-16 11:44:45 +08:00
parent 83951c1cf4
commit fd46811f33
5 changed files with 28 additions and 617 deletions

View File

@ -24,178 +24,20 @@
#include "securec.h"
#include "define.h"
#include "wifi_manager_service_ipc_interface_code.h"
#include "wifi_device_service_impl.h"
#include "wifi_log.h"
namespace OHOS {
namespace Wifi {
constexpr size_t FOO_MAX_LEN = 1024;
constexpr size_t U32_AT_SIZE = 4;
constexpr size_t U32_AT_SIZE_ZERO = 0;
constexpr size_t MAP_DEVICE_NUMS = 50;
const std::u16string FORMMGR_INTERFACE_TOKEN = u"ohos.wifi.IWifiDeviceService";
class WifiDeviceStubFuzzTest : public WifiDeviceStub {
public:
WifiDeviceStubFuzzTest() = default;
virtual ~WifiDeviceStubFuzzTest() = default;
ErrCode EnableWifi() override
{
return WIFI_OPT_SUCCESS;
}
ErrCode DisableWifi() override
{
return WIFI_OPT_SUCCESS;
}
ErrCode InitWifiProtect(const WifiProtectType &protectType, const std::string &protectName) override
{
return WIFI_OPT_SUCCESS;
}
ErrCode GetWifiProtectRef(const WifiProtectMode &protectMode, const std::string &protectName) override
{
return WIFI_OPT_SUCCESS;
}
ErrCode PutWifiProtectRef(const std::string &protectName) override
{
return WIFI_OPT_SUCCESS;
}
ErrCode RemoveCandidateConfig(int networkId) override
{
return WIFI_OPT_SUCCESS;
}
ErrCode RemoveCandidateConfig(const WifiDeviceConfig &config) override
{
return WIFI_OPT_SUCCESS;
}
ErrCode AddDeviceConfig(const WifiDeviceConfig &config, int &result, bool isCandidate) override
{
return WIFI_OPT_SUCCESS;
}
ErrCode UpdateDeviceConfig(const WifiDeviceConfig &config, int &result) override
{
return WIFI_OPT_SUCCESS;
}
ErrCode RemoveDevice(int networkId) override
{
return WIFI_OPT_SUCCESS;
}
ErrCode RemoveAllDevice() override
{
return WIFI_OPT_SUCCESS;
}
ErrCode GetDeviceConfigs(std::vector<WifiDeviceConfig> &result, bool isCandidate) override
{
return WIFI_OPT_SUCCESS;
}
ErrCode EnableDeviceConfig(int networkId, bool attemptEnable) override
{
return WIFI_OPT_SUCCESS;
}
ErrCode DisableDeviceConfig(int networkId) override
{
return WIFI_OPT_SUCCESS;
}
ErrCode ConnectToNetwork(int networkId, bool isCandidate) override
{
return WIFI_OPT_SUCCESS;
}
ErrCode ConnectToDevice(const WifiDeviceConfig &config) override
{
return WIFI_OPT_SUCCESS;
}
ErrCode IsConnected(bool &isConnected) override
{
return WIFI_OPT_SUCCESS;
}
ErrCode ReConnect() override
{
return WIFI_OPT_SUCCESS;
}
ErrCode ReAssociate(void) override
{
return WIFI_OPT_SUCCESS;
}
ErrCode Disconnect(void) override
{
return WIFI_OPT_SUCCESS;
}
ErrCode StartWps(const WpsConfig &config) override
{
return WIFI_OPT_SUCCESS;
}
ErrCode CancelWps(void) override
{
return WIFI_OPT_SUCCESS;
}
ErrCode IsWifiActive(bool &bActive) override
{
return WIFI_OPT_SUCCESS;
}
ErrCode GetWifiState(int &state) override
{
return WIFI_OPT_SUCCESS;
}
ErrCode GetLinkedInfo(WifiLinkedInfo &info) override
{
return WIFI_OPT_SUCCESS;
}
ErrCode GetDisconnectedReason(DisconnectedReason &reason) override
{
return WIFI_OPT_SUCCESS;
}
ErrCode GetIpInfo(IpInfo &info) override
{
return WIFI_OPT_SUCCESS;
}
ErrCode GetIpv6Info(IpV6Info &info) override
{
return WIFI_OPT_SUCCESS;
}
ErrCode SetCountryCode(const std::string &countryCode) override
{
return WIFI_OPT_SUCCESS;
}
ErrCode GetCountryCode(std::string &countryCode) override
{
return WIFI_OPT_SUCCESS;
}
ErrCode RegisterCallBack(const sptr<IWifiDeviceCallBack> &callback, const std::vector<std::string> &event) override
{
return WIFI_OPT_SUCCESS;
}
ErrCode GetSignalLevel(const int &rssi, const int &band, int &level) override
{
return WIFI_OPT_SUCCESS;
}
ErrCode GetSupportedFeatures(long &features) override
{
return WIFI_OPT_SUCCESS;
}
ErrCode GetDeviceMacAddress(std::string &result) override
{
return WIFI_OPT_SUCCESS;
}
bool SetLowLatencyMode(bool enabled) override
{
return WIFI_OPT_SUCCESS;
}
bool IsRemoteDied(void) override
{
return WIFI_OPT_SUCCESS;
}
ErrCode IsBandTypeSupported(int bandType, bool &supported) override
{
return WIFI_OPT_SUCCESS;
}
ErrCode Get5GHzChannelList(std::vector<int> &result) override
{
return WIFI_OPT_SUCCESS;
}
};
sptr<WifiDeviceStub> pWifiDeviceStub = WifiDeviceServiceImpl::GetInstance();
bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size)
{
uint32_t code = U32_AT(data) % MAP_DEVICE_NUMS + static_cast<uint32_t>(DevInterfaceCode::WIFI_SVR_CMD_ENABLE_WIFI);
LOGI("wifidevicestub_fuzzer code(0x%{public}x)", code); // code[0x1001,0x1031]
LOGI("wifidevicestub_fuzzer code(0x%{public}x) size(%{public}zu)", code, size); // code[0x1001,0x1031]
MessageParcel datas;
datas.WriteInterfaceToken(FORMMGR_INTERFACE_TOKEN);
datas.WriteInt32(0);
@ -203,7 +45,6 @@ bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size)
datas.RewindRead(0);
MessageParcel reply;
MessageOption option;
std::shared_ptr<WifiDeviceStub> pWifiDeviceStub = std::make_shared<WifiDeviceStubFuzzTest>();
pWifiDeviceStub->OnRemoteRequest(code, datas, reply, option);
return true;
}
@ -211,22 +52,11 @@ bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size)
/* Fuzzer entry point */
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
{
/* Run your code on data */
if (data == nullptr) {
if ((data == nullptr) || (size <= OHOS::Wifi::U32_AT_SIZE_ZERO)) {
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(data, size);
return 0;
}
}
}
}

View File

@ -27,8 +27,10 @@ ohos_fuzztest("WifiHotSpotStubFuzzTest") {
"$WIFI_ROOT_DIR/interfaces/inner_api",
"$WIFI_ROOT_DIR/frameworks/native/include",
"$WIFI_ROOT_DIR/frameworks/native/interfaces",
"$WIFI_ROOT_DIR/services/wifi_standard/include",
"$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/services/wifi_standard/wifi_framework/wifi_toolkit/config",
"$WIFI_ROOT_DIR/test/fuzztest/fuzz_common_func",
]

View File

@ -24,125 +24,15 @@
#include "securec.h"
#include "define.h"
#include "wifi_manager_service_ipc_interface_code.h"
#include "wifi_hotspot_service_impl.h"
#include "wifi_log.h"
namespace OHOS {
namespace Wifi {
constexpr size_t FOO_MAX_LEN = 1024;
constexpr size_t U32_AT_SIZE = 4;
constexpr size_t U32_AT_SIZE_ZERO = 0;
constexpr size_t MAP_HOTSPOT_NUMS = 22;
const std::u16string FORMMGR_INTERFACE_TOKEN = u"ohos.wifi.IWifiHotspotService";
class WifiHotSpotStubFuzzTest : public WifiHotspotStub {
public:
WifiHotSpotStubFuzzTest() = default;
virtual ~WifiHotSpotStubFuzzTest() = default;
ErrCode IsHotspotActive(bool &bActive) override
{
return WIFI_OPT_SUCCESS;
}
ErrCode IsHotspotDualBandSupported(bool &isSupported) override
{
return WIFI_OPT_SUCCESS;
}
ErrCode GetHotspotConfig(HotspotConfig &config) override
{
return WIFI_OPT_SUCCESS;
}
ErrCode GetHotspotState(int &state) override
{
return WIFI_OPT_SUCCESS;
}
ErrCode SetHotspotConfig(const HotspotConfig &config) override
{
return WIFI_OPT_SUCCESS;
}
ErrCode SetHotspotIdleTimeout(int time) override
{
return WIFI_OPT_SUCCESS;
}
ErrCode GetStationList(std::vector<StationInfo> &result) override
{
return WIFI_OPT_SUCCESS;
}
ErrCode DisassociateSta(const StationInfo &info) override
{
return WIFI_OPT_SUCCESS;
}
ErrCode EnableHotspot(const ServiceType type = ServiceType::DEFAULT) override
{
return WIFI_OPT_SUCCESS;
}
ErrCode DisableHotspot(const ServiceType type = ServiceType::DEFAULT) override
{
return WIFI_OPT_SUCCESS;
}
ErrCode GetBlockLists(std::vector<StationInfo> &infos) override
{
return WIFI_OPT_SUCCESS;
}
ErrCode AddBlockList(const StationInfo &info) override
{
return WIFI_OPT_SUCCESS;
}
ErrCode DelBlockList(const StationInfo &info) override
{
return WIFI_OPT_SUCCESS;
}
ErrCode GetValidBands(std::vector<BandType> &bands) override
{
return WIFI_OPT_SUCCESS;
}
ErrCode GetValidChannels(BandType band, std::vector<int32_t> &validchannels) override
{
return WIFI_OPT_SUCCESS;
}
ErrCode RegisterCallBack(const sptr<IWifiHotspotCallback> &callback,
const std::vector<std::string> &event) override
{
return WIFI_OPT_SUCCESS;
}
ErrCode GetSupportedFeatures(long &features) override
{
return WIFI_OPT_SUCCESS;
}
ErrCode GetSupportedPowerModel(std::set<PowerModel>& setPowerModelList) override
{
return WIFI_OPT_SUCCESS;
}
ErrCode GetPowerModel(PowerModel& model) override
{
return WIFI_OPT_SUCCESS;
}
ErrCode SetPowerModel(const PowerModel& model) override
{
return WIFI_OPT_SUCCESS;
}
bool IsRemoteDied() override
{
return true;
}
};
std::shared_ptr<WifiHotspotStub> pWifiHotspotStub = std::make_shared<WifiHotspotServiceImpl>();
void OnGetSupportedFeaturesTest(const uint8_t* data, size_t size)
{
@ -153,7 +43,6 @@ void OnGetSupportedFeaturesTest(const uint8_t* data, size_t size)
datas.RewindRead(0);
MessageParcel reply;
MessageOption option;
std::shared_ptr<WifiHotspotStub> pWifiHotspotStub = std::make_shared<WifiHotSpotStubFuzzTest>();
pWifiHotspotStub->OnRemoteRequest(static_cast<uint32_t>(DevInterfaceCode::WIFI_SVR_CMD_GET_SUPPORTED_FEATURES),
datas, reply, option);
}
@ -162,6 +51,7 @@ bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size)
{
uint32_t code = U32_AT(data) % MAP_HOTSPOT_NUMS +
static_cast<uint32_t>(HotspotInterfaceCode::WIFI_SVR_CMD_ENABLE_WIFI_AP);
LOGI("wifihotspotstub_fuzzer code(0x%{public}x) size(%{public}zu)", code, size);
MessageParcel datas;
datas.WriteInterfaceToken(FORMMGR_INTERFACE_TOKEN);
datas.WriteInt32(0);
@ -169,30 +59,17 @@ bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size)
datas.RewindRead(0);
MessageParcel reply;
MessageOption option;
std::shared_ptr<WifiHotspotStub> pWifiHotspotStub = std::make_shared<WifiHotSpotStubFuzzTest>();
OnGetSupportedFeaturesTest(data, size);
pWifiHotspotStub->OnRemoteRequest(code, datas, reply, option);
OnGetSupportedFeaturesTest(data, size);
return true;
}
/* Fuzzer entry point */
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
{
/* Run your code on data */
if (data == nullptr) {
if ((data == nullptr) || (size <= OHOS::Wifi::U32_AT_SIZE_ZERO)) {
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(data, size);
return 0;
}

View File

@ -24,242 +24,15 @@
#include "securec.h"
#include "define.h"
#include "wifi_manager_service_ipc_interface_code.h"
#include "wifi_p2p_service_impl.h"
#include "wifi_log.h"
namespace OHOS {
namespace Wifi {
constexpr size_t FOO_MAX_LEN = 1024;
constexpr size_t U32_AT_SIZE = 4;
constexpr size_t U32_AT_SIZE_ZERO = 0;
constexpr size_t MAP_P2P_NUMS = 41;
const std::u16string FORMMGR_INTERFACE_TOKEN = u"ohos.wifi.IWifiP2pService";
class WifiP2pStubFuzzTest : public WifiP2pStub {
public:
WifiP2pStubFuzzTest() = default;
virtual ~WifiP2pStubFuzzTest() = 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 GetP2pConnectedStatus(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 Hid2dRemoveGcGroup(const std::string& gcIfName) 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;
}
};
sptr<WifiP2pStub> pWifiP2pStub = WifiP2pServiceImpl::GetInstance();
void OnGetSupportedFeaturesTest(const uint8_t* data, size_t size)
{
@ -270,7 +43,6 @@ void OnGetSupportedFeaturesTest(const uint8_t* data, size_t size)
datas.RewindRead(0);
MessageParcel reply;
MessageOption option;
std::shared_ptr<WifiP2pStub> pWifiP2pStub = std::make_shared<WifiP2pStubFuzzTest>();
pWifiP2pStub->OnRemoteRequest(static_cast<uint32_t>(DevInterfaceCode::WIFI_SVR_CMD_GET_SUPPORTED_FEATURES),
datas, reply, option);
}
@ -278,6 +50,7 @@ void OnGetSupportedFeaturesTest(const uint8_t* data, size_t size)
bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size)
{
uint32_t code = U32_AT(data) % MAP_P2P_NUMS + static_cast<uint32_t>(P2PInterfaceCode::WIFI_SVR_CMD_P2P_ENABLE);
LOGI("wifip2pstub_fuzzer code(0x%{public}x) size(%{public}zu)", code, size);
MessageParcel datas;
datas.WriteInterfaceToken(FORMMGR_INTERFACE_TOKEN);
datas.WriteInt32(0);
@ -285,29 +58,17 @@ bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size)
datas.RewindRead(0);
MessageParcel reply;
MessageOption option;
std::shared_ptr<WifiP2pStub> pWifiP2pStub = std::make_shared<WifiP2pStubFuzzTest>();
OnGetSupportedFeaturesTest(data, size);
pWifiP2pStub->OnRemoteRequest(code, datas, reply, option);
OnGetSupportedFeaturesTest(data, size);
return true;
}
/* Fuzzer entry point */
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
{
/* Run your code on data */
if (data == nullptr) {
if ((data == nullptr) || (size <= OHOS::Wifi::U32_AT_SIZE_ZERO)) {
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(data, size);
return 0;
}

View File

@ -24,61 +24,15 @@
#include "securec.h"
#include "define.h"
#include "wifi_manager_service_ipc_interface_code.h"
#include "wifi_scan_service_impl.h"
#include "wifi_log.h"
namespace OHOS {
namespace Wifi {
constexpr size_t FOO_MAX_LEN = 1024;
constexpr size_t U32_AT_SIZE = 4;
constexpr size_t U32_AT_SIZE_ZERO = 0;
constexpr size_t MAP_SCAN_NUMS = 31;
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 &params) 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;
}
ErrCode SetScanOnlyAvailable(bool bScanOnlyAvailable) override
{
return WIFI_OPT_SUCCESS;
}
ErrCode GetScanOnlyAvailable(bool &bScanOnlyAvailable) override
{
return WIFI_OPT_SUCCESS;
}
};
sptr<WifiScanStub> pWifiScanStub = WifiScanServiceImpl::GetInstance();
void OnGetSupportedFeaturesTest(const uint8_t* data, size_t size)
{
@ -89,7 +43,6 @@ void OnGetSupportedFeaturesTest(const uint8_t* data, size_t size)
datas.RewindRead(0);
MessageParcel reply;
MessageOption option;
std::shared_ptr<WifiScanStub> pWifiScanStub = std::make_shared<WifiScanStubTest>();
pWifiScanStub->OnRemoteRequest(static_cast<uint32_t>(DevInterfaceCode::WIFI_SVR_CMD_GET_SUPPORTED_FEATURES),
datas, reply, option);
}
@ -97,7 +50,7 @@ void OnGetSupportedFeaturesTest(const uint8_t* data, size_t size)
bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size)
{
uint32_t code = U32_AT(data) % MAP_SCAN_NUMS + static_cast<uint32_t>(ScanInterfaceCode::WIFI_SVR_CMD_FULL_SCAN);
LOGI("wifiscanstub_fuzzer code(0x%{public}x)", code); // code[0x1004, 0x101E]
LOGI("wifiscanstub_fuzzer code(0x%{public}x) size(%{public}zu)", code, size); // code[0x1004, 0x101E]
MessageParcel datas;
datas.WriteInterfaceToken(FORMMGR_INTERFACE_TOKEN);
datas.WriteInt32(0);
@ -105,29 +58,17 @@ bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size)
datas.RewindRead(0);
MessageParcel reply;
MessageOption option;
std::shared_ptr<WifiScanStub> pWifiScanStub = std::make_shared<WifiScanStubTest>();
OnGetSupportedFeaturesTest(data, size);
pWifiScanStub->OnRemoteRequest(code, datas, reply, option);
OnGetSupportedFeaturesTest(data, size);
return true;
}
/* Fuzzer entry point */
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
{
/* Run your code on data */
if (data == nullptr) {
if ((data == nullptr) || (size <= OHOS::Wifi::U32_AT_SIZE_ZERO)) {
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(data, size);
return 0;
}