add wifi fuzzer testcases

Signed-off-by: z00588131 <hw.zhangfeng@huawei.com>
This commit is contained in:
z00588131 2022-05-27 14:48:18 +08:00
parent b8e89e4853
commit ecc9192509
13 changed files with 373 additions and 0 deletions

View File

@ -105,6 +105,7 @@
}
],
"test": [
"//foundation/communication/wifi/wifi/test/fuzztest/wifi_sta:fuzztest"
]
},
"hisysevent_config": [

View File

@ -0,0 +1,35 @@
/*
* 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_COMMON_FUNC_H_
#define WIFI_FUZZ_COMMON_FUNC_H_
#include <cstdint>
namespace OHOS {
namespace Wifi {
inline uint16_t U16_AT(const uint8_t* data)
{
return (data[0] << 8) | data[1];
}
inline uint32_t U32_AT(const uint8_t* data)
{
return (data[0] << 24) | (data[1] << 16) | (data[2] << 8) | data[3];
}
} // namespace Wifi
} // namespace OHOS
#endif

View File

@ -0,0 +1,23 @@
# 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 += [
"adddeviceconfig_fuzzer:AddDeviceConfigFuzzTest",
"connecttodevice_fuzzer:ConnectToDeviceFuzzTest",
]
}

View File

@ -0,0 +1,50 @@
# 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("AddDeviceConfigFuzzTest") {
module_out_path = module_output_path
fuzz_config_file =
"$WIFI_ROOT_DIR/test/fuzztest/wifi_sta/adddeviceconfig_fuzzer"
include_dirs = [
"$WIFI_ROOT_DIR/frameworks/native/include",
"$WIFI_ROOT_DIR/frameworks/native/interfaces",
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/common/net_helper",
"$WIFI_ROOT_DIR/test/fuzztest/fuzz_common_func",
]
cflags = [
"-g",
"-O0",
"-Wno-unused-variable",
"-fno-omit-frame-pointer",
]
sources = [ "adddeviceconfig_fuzzer.cpp" ]
deps = [
"$WIFI_ROOT_DIR/frameworks/native:wifi_sdk",
"//utils/native/base:utils",
]
external_deps = [ "ipc:ipc_core" ]
part_name = "wifi"
subsystem_name = "communication"
}

View File

@ -0,0 +1,45 @@
/*
* 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.
*/
#include "adddeviceconfig_fuzzer.h"
#include "wifi_device.h"
namespace OHOS {
namespace Wifi {
bool AddDeviceConfigFuzzerTest(const uint8_t* data, size_t size)
{
std::unique_ptr<WifiDevice> devicePtr = WifiDevice::GetInstance(WIFI_DEVICE_ABILITY_ID);
if (devicePtr == nullptr) {
return false;
}
WifiDeviceConfig config;
int addResult;
config.ssid = std::string(reinterpret_cast<const char*>(data), size);
config.bssid = std::string(reinterpret_cast<const char*>(data), size);
config.preSharedKey = std::string(reinterpret_cast<const char*>(data), size);
config.keyMgmt = std::string(reinterpret_cast<const char*>(data), size);
devicePtr->AddDeviceConfig(config, addResult);
return true;
}
} // namespace Wifi
} // namespace OHOS
/* Fuzzer entry point */
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
{
OHOS::Wifi::AddDeviceConfigFuzzerTest(data, 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_ADD_DEVICE_CONFIG_H_
#define WIFI_FUZZ_ADD_DEVICE_CONFIG_H_
#define FUZZ_PROJECT_NAME "adddeviceconfig_fuzzer"
#endif

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,50 @@
# 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("ConnectToDeviceFuzzTest") {
module_out_path = module_output_path
fuzz_config_file =
"$WIFI_ROOT_DIR/test/fuzztest/wifi_sta/connecttodevice_fuzzer"
include_dirs = [
"$WIFI_ROOT_DIR/frameworks/native/include",
"$WIFI_ROOT_DIR/frameworks/native/interfaces",
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/common/net_helper",
"$WIFI_ROOT_DIR/test/fuzztest/fuzz_common_func",
]
cflags = [
"-g",
"-O0",
"-Wno-unused-variable",
"-fno-omit-frame-pointer",
]
sources = [ "connecttodevice_fuzzer.cpp" ]
deps = [
"$WIFI_ROOT_DIR/frameworks/native:wifi_sdk",
"//utils/native/base:utils",
]
external_deps = [ "ipc:ipc_core" ]
part_name = "wifi"
subsystem_name = "communication"
}

View File

@ -0,0 +1,45 @@
/*
* 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.
*/
#include "connecttodevice_fuzzer.h"
#include "wifi_device.h"
namespace OHOS {
namespace Wifi {
bool ConnectToDeviceFuzzerTest(const uint8_t* data, size_t size)
{
std::unique_ptr<WifiDevice> devicePtr = WifiDevice::GetInstance(WIFI_DEVICE_ABILITY_ID);
if (devicePtr == nullptr) {
return false;
}
WifiDeviceConfig config;
config.ssid = std::string(reinterpret_cast<const char*>(data), size);
config.bssid = std::string(reinterpret_cast<const char*>(data), size);
config.preSharedKey = std::string(reinterpret_cast<const char*>(data), size);
config.keyMgmt = std::string(reinterpret_cast<const char*>(data), size);
devicePtr->ConnectToDevice(config);
return true;
}
} // namespace Wifi
} // namespace OHOS
/* Fuzzer entry point */
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
{
OHOS::Wifi::ConnectToDeviceFuzzerTest(data, 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_CONNECT_TO_DEVICE_H_
#define WIFI_FUZZ_CONNECT_TO_DEVICE_H_
#define FUZZ_PROJECT_NAME "connecttodevice_fuzzer"
#endif

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>