add fuzz test cases

Signed-off-by: wu-chengwen <wuchengwen4@huawei.com>
This commit is contained in:
wu-chengwen
2022-05-05 10:14:24 +08:00
parent bc62f26082
commit 08a25182bf
29 changed files with 1537 additions and 0 deletions
+691
View File
@@ -0,0 +1,691 @@
# 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("//base/usb/usb_manager/usbmgr.gni")
import("//build/config/features.gni")
import("//build/test.gni")
module_output_path = "${usb_manager_part_name}/usb_fuzztest_test"
config("module_private_config") {
visibility = [ ":*" ]
configs = [ "${utils_path}:utils_config" ]
cflags = [
"-g",
"-O0",
"-Wno-unused-variable",
"-fno-omit-frame-pointer",
]
include_dirs = [
"include",
"common/include",
"${usb_manager_path}/test/common/include/",
]
}
ohos_fuzztest("UsbMgrRequestRightFuzzTest") {
module_out_path = module_output_path
fuzz_config_file =
"${usb_manager_path}/test/fuzztest/usbmgrrequestright_fuzzer"
configs = [ ":module_private_config" ]
deps = [
"${usb_manager_path}/interfaces/innerkits:usbsrv_client",
"${usb_manager_path}/services:usbservice",
]
external_deps = [
"hiviewdfx_hilog_native:libhilog",
"ipc:ipc_core",
"usb_device_driver:usbd_client",
"utils_base:utils",
]
sources = [ "usbmgrrequestright_fuzzer/usbmgrrequestright_fuzzer.cpp" ]
}
ohos_fuzztest("UsbMgrHasRightFuzzTest") {
module_out_path = module_output_path
fuzz_config_file = "${usb_manager_path}/test/fuzztest/usbmgrhasright_fuzzer"
configs = [ ":module_private_config" ]
deps = [
"${usb_manager_path}/interfaces/innerkits:usbsrv_client",
"${usb_manager_path}/services:usbservice",
]
external_deps = [
"hiviewdfx_hilog_native:libhilog",
"ipc:ipc_core",
"usb_device_driver:usbd_client",
"utils_base:utils",
]
sources = [ "usbmgrhasright_fuzzer/usbmgrhasright_fuzzer.cpp" ]
}
ohos_fuzztest("UsbMgrRemoveRightFuzzTest") {
module_out_path = module_output_path
fuzz_config_file =
"${usb_manager_path}/test/fuzztest/usbmgrremoveright_fuzzer"
configs = [ ":module_private_config" ]
deps = [
"${usb_manager_path}/interfaces/innerkits:usbsrv_client",
"${usb_manager_path}/services:usbservice",
]
external_deps = [
"hiviewdfx_hilog_native:libhilog",
"ipc:ipc_core",
"usb_device_driver:usbd_client",
"utils_base:utils",
]
sources = [ "usbmgrremoveright_fuzzer/usbmgrremoveright_fuzzer.cpp" ]
}
ohos_fuzztest("UsbMgrGetSupportedModesFuzzTest") {
module_out_path = module_output_path
fuzz_config_file =
"${usb_manager_path}/test/fuzztest/usbmgrgetsupportedmodes_fuzzer"
configs = [ ":module_private_config" ]
deps = [
"${usb_manager_path}/interfaces/innerkits:usbsrv_client",
"${usb_manager_path}/services:usbservice",
]
external_deps = [
"hiviewdfx_hilog_native:libhilog",
"ipc:ipc_core",
"usb_device_driver:usbd_client",
"utils_base:utils",
]
sources =
[ "usbmgrgetsupportedmodes_fuzzer/usbmgrgetsupportedmodes_fuzzer.cpp" ]
}
ohos_fuzztest("UsbMgrSetPortRoleFuzzTest") {
module_out_path = module_output_path
fuzz_config_file =
"${usb_manager_path}/test/fuzztest/usbmgrsetportrole_fuzzer"
configs = [ ":module_private_config" ]
deps = [
"${usb_manager_path}/interfaces/innerkits:usbsrv_client",
"${usb_manager_path}/services:usbservice",
]
external_deps = [
"hiviewdfx_hilog_native:libhilog",
"ipc:ipc_core",
"usb_device_driver:usbd_client",
"utils_base:utils",
]
sources = [ "usbmgrsetportrole_fuzzer/usbmgrsetportrole_fuzzer.cpp" ]
}
ohos_fuzztest("UsbMgrSetCurrentFunctionsFuzzTest") {
module_out_path = module_output_path
fuzz_config_file =
"${usb_manager_path}/test/fuzztest/usbmgrsetcurrentfunctions_fuzzer"
configs = [ ":module_private_config" ]
deps = [
"${usb_manager_path}/interfaces/innerkits:usbsrv_client",
"${usb_manager_path}/services:usbservice",
]
external_deps = [
"hiviewdfx_hilog_native:libhilog",
"ipc:ipc_core",
"usb_device_driver:usbd_client",
"utils_base:utils",
]
sources = [
"usbmgrsetcurrentfunctions_fuzzer/usbmgrsetcurrentfunctions_fuzzer.cpp",
]
}
ohos_fuzztest("UsbMgrUsbFunctionsFromStringFuzzTest") {
module_out_path = module_output_path
fuzz_config_file =
"${usb_manager_path}/test/fuzztest/usbmgrusbfunctionsfromstring_fuzzer"
configs = [ ":module_private_config" ]
deps = [
"${usb_manager_path}/interfaces/innerkits:usbsrv_client",
"${usb_manager_path}/services:usbservice",
]
external_deps = [
"hiviewdfx_hilog_native:libhilog",
"ipc:ipc_core",
"usb_device_driver:usbd_client",
"utils_base:utils",
]
sources = [ "usbmgrusbfunctionsfromstring_fuzzer/usbmgrusbfunctionsfromstring_fuzzer.cpp" ]
}
ohos_fuzztest("UsbMgrUsbFunctionsToStringFuzzTest") {
module_out_path = module_output_path
fuzz_config_file =
"${usb_manager_path}/test/fuzztest/usbmgrusbfunctionstostring_fuzzer"
configs = [ ":module_private_config" ]
deps = [
"${usb_manager_path}/interfaces/innerkits:usbsrv_client",
"${usb_manager_path}/services:usbservice",
]
external_deps = [
"hiviewdfx_hilog_native:libhilog",
"ipc:ipc_core",
"usb_device_driver:usbd_client",
"utils_base:utils",
]
sources = [
"usbmgrusbfunctionstostring_fuzzer/usbmgrusbfunctionstostring_fuzzer.cpp",
]
}
ohos_fuzztest("UsbMgrClaimInterfaceFuzzTest") {
module_out_path = module_output_path
fuzz_config_file =
"${usb_manager_path}/test/fuzztest/usbmgrclaiminterface_fuzzer"
configs = [ ":module_private_config" ]
deps = [
"${usb_manager_path}/interfaces/innerkits:usbsrv_client",
"${usb_manager_path}/services:usbservice",
]
external_deps = [
"hiviewdfx_hilog_native:libhilog",
"ipc:ipc_core",
"usb_device_driver:usbd_client",
"utils_base:utils",
]
sources = [ "usbmgrclaiminterface_fuzzer/usbmgrclaiminterface_fuzzer.cpp" ]
}
ohos_fuzztest("UsbMgrReleaseInterfaceFuzzTest") {
module_out_path = module_output_path
fuzz_config_file =
"${usb_manager_path}/test/fuzztest/usbmgrreleaseinterface_fuzzer"
configs = [ ":module_private_config" ]
deps = [
"${usb_manager_path}/interfaces/innerkits:usbsrv_client",
"${usb_manager_path}/services:usbservice",
]
external_deps = [
"hiviewdfx_hilog_native:libhilog",
"ipc:ipc_core",
"usb_device_driver:usbd_client",
"utils_base:utils",
]
sources =
[ "usbmgrreleaseinterface_fuzzer/usbmgrreleaseinterface_fuzzer.cpp" ]
}
ohos_fuzztest("UsbMgrBulkTransferFuzzTest") {
module_out_path = module_output_path
fuzz_config_file =
"${usb_manager_path}/test/fuzztest/usbmgrbultransfer_fuzzer"
configs = [ ":module_private_config" ]
deps = [
"${usb_manager_path}/interfaces/innerkits:usbsrv_client",
"${usb_manager_path}/services:usbservice",
]
external_deps = [
"hiviewdfx_hilog_native:libhilog",
"ipc:ipc_core",
"usb_device_driver:usbd_client",
"utils_base:utils",
]
sources = [ "usbmgrbultransfer_fuzzer/usbmgrbultransfer_fuzzer.cpp" ]
}
ohos_fuzztest("UsbMgrControlTransferFuzzTest") {
module_out_path = module_output_path
fuzz_config_file =
"${usb_manager_path}/test/fuzztest/usbmgrcontroltransfer_fuzzer"
configs = [ ":module_private_config" ]
deps = [
"${usb_manager_path}/interfaces/innerkits:usbsrv_client",
"${usb_manager_path}/services:usbservice",
]
external_deps = [
"hiviewdfx_hilog_native:libhilog",
"ipc:ipc_core",
"usb_device_driver:usbd_client",
"utils_base:utils",
]
sources = [ "usbmgrcontroltransfer_fuzzer/usbmgrcontroltransfer_fuzzer.cpp" ]
}
ohos_fuzztest("UsbMgrSetConfigurationFuzzTest") {
module_out_path = module_output_path
fuzz_config_file =
"${usb_manager_path}/test/fuzztest/usbmgrsetconfiguration_fuzzer"
configs = [ ":module_private_config" ]
deps = [
"${usb_manager_path}/interfaces/innerkits:usbsrv_client",
"${usb_manager_path}/services:usbservice",
]
external_deps = [
"hiviewdfx_hilog_native:libhilog",
"ipc:ipc_core",
"usb_device_driver:usbd_client",
"utils_base:utils",
]
sources =
[ "usbmgrsetconfiguration_fuzzer/usbmgrsetconfiguration_fuzzer.cpp" ]
}
ohos_fuzztest("UsbMgrSetInterfaceFuzzTest") {
module_out_path = module_output_path
fuzz_config_file =
"${usb_manager_path}/test/fuzztest/usbmgrsetinterface_fuzzer"
configs = [ ":module_private_config" ]
deps = [
"${usb_manager_path}/interfaces/innerkits:usbsrv_client",
"${usb_manager_path}/services:usbservice",
]
external_deps = [
"hiviewdfx_hilog_native:libhilog",
"ipc:ipc_core",
"usb_device_driver:usbd_client",
"utils_base:utils",
]
sources = [ "usbmgrsetinterface_fuzzer/usbmgrsetinterface_fuzzer.cpp" ]
}
ohos_fuzztest("UsbMgrGetRawDescriptorsFuzzTest") {
module_out_path = module_output_path
fuzz_config_file =
"${usb_manager_path}/test/fuzztest/usbmgrgetrawdescriptors_fuzzer"
configs = [ ":module_private_config" ]
deps = [
"${usb_manager_path}/interfaces/innerkits:usbsrv_client",
"${usb_manager_path}/services:usbservice",
]
external_deps = [
"hiviewdfx_hilog_native:libhilog",
"ipc:ipc_core",
"usb_device_driver:usbd_client",
"utils_base:utils",
]
sources =
[ "usbmgrgetrawdescriptors_fuzzer/usbmgrgetrawdescriptors_fuzzer.cpp" ]
}
ohos_fuzztest("UsbMgrGetFileDescriptorFuzzTest") {
module_out_path = module_output_path
fuzz_config_file =
"${usb_manager_path}/test/fuzztest/usbmgrgetfiledescriptor_fuzzer"
configs = [ ":module_private_config" ]
deps = [
"${usb_manager_path}/interfaces/innerkits:usbsrv_client",
"${usb_manager_path}/services:usbservice",
]
external_deps = [
"hiviewdfx_hilog_native:libhilog",
"ipc:ipc_core",
"usb_device_driver:usbd_client",
"utils_base:utils",
]
sources =
[ "usbmgrgetfiledescriptor_fuzzer/usbmgrgetfiledescriptor_fuzzer.cpp" ]
}
ohos_fuzztest("UsbMgrCloseFuzzTest") {
module_out_path = module_output_path
fuzz_config_file = "${usb_manager_path}/test/fuzztest/usbmgrclose_fuzzer"
configs = [ ":module_private_config" ]
deps = [
"${usb_manager_path}/interfaces/innerkits:usbsrv_client",
"${usb_manager_path}/services:usbservice",
]
external_deps = [
"hiviewdfx_hilog_native:libhilog",
"ipc:ipc_core",
"usb_device_driver:usbd_client",
"utils_base:utils",
]
sources = [ "usbmgrclose_fuzzer/usbmgrclose_fuzzer.cpp" ]
}
ohos_fuzztest("UsbMgrPipeRequestWaitFuzzTest") {
module_out_path = module_output_path
fuzz_config_file =
"${usb_manager_path}/test/fuzztest/usbmgrpiperequestwait_fuzzer"
configs = [ ":module_private_config" ]
deps = [
"${usb_manager_path}/interfaces/innerkits:usbsrv_client",
"${usb_manager_path}/services:usbservice",
]
external_deps = [
"hiviewdfx_hilog_native:libhilog",
"ipc:ipc_core",
"usb_device_driver:usbd_client",
"utils_base:utils",
]
sources = [ "usbmgrpiperequestwait_fuzzer/usbmgrpiperequestwait_fuzzer.cpp" ]
}
ohos_fuzztest("UsbMgrRequestInitializeFuzzTest") {
module_out_path = module_output_path
fuzz_config_file =
"${usb_manager_path}/test/fuzztest/usbmgrrequestinitialize_fuzzer"
configs = [ ":module_private_config" ]
deps = [
"${usb_manager_path}/interfaces/innerkits:usbsrv_client",
"${usb_manager_path}/services:usbservice",
]
external_deps = [
"hiviewdfx_hilog_native:libhilog",
"ipc:ipc_core",
"usb_device_driver:usbd_client",
"utils_base:utils",
]
sources =
[ "usbmgrrequestinitialize_fuzzer/usbmgrrequestinitialize_fuzzer.cpp" ]
}
ohos_fuzztest("UsbMgrRequestQueueFuzzTest") {
module_out_path = module_output_path
fuzz_config_file =
"${usb_manager_path}/test/fuzztest/usbmgrrequestqueue_fuzzer"
configs = [ ":module_private_config" ]
deps = [
"${usb_manager_path}/interfaces/innerkits:usbsrv_client",
"${usb_manager_path}/services:usbservice",
]
external_deps = [
"hiviewdfx_hilog_native:libhilog",
"ipc:ipc_core",
"usb_device_driver:usbd_client",
"utils_base:utils",
]
sources = [ "usbmgrrequestqueue_fuzzer/usbmgrrequestqueue_fuzzer.cpp" ]
}
ohos_fuzztest("UsbMgrRequestFreeFuzzTest") {
module_out_path = module_output_path
fuzz_config_file =
"${usb_manager_path}/test/fuzztest/usbmgrrequestfree_fuzzer"
configs = [ ":module_private_config" ]
deps = [
"${usb_manager_path}/interfaces/innerkits:usbsrv_client",
"${usb_manager_path}/services:usbservice",
]
external_deps = [
"hiviewdfx_hilog_native:libhilog",
"ipc:ipc_core",
"usb_device_driver:usbd_client",
"utils_base:utils",
]
sources = [ "usbmgrrequestfree_fuzzer/usbmgrrequestfree_fuzzer.cpp" ]
}
ohos_fuzztest("UsbMgrRegBulkCallbackFuzzTest") {
module_out_path = module_output_path
fuzz_config_file =
"${usb_manager_path}/test/fuzztest/usbmgrregbulkcallback_fuzzer"
configs = [ ":module_private_config" ]
deps = [
"${usb_manager_path}/interfaces/innerkits:usbsrv_client",
"${usb_manager_path}/services:usbservice",
]
external_deps = [
"hiviewdfx_hilog_native:libhilog",
"ipc:ipc_core",
"usb_device_driver:usbd_client",
"utils_base:utils",
]
sources = [
"common/src/usb_common_fuzz.cpp",
"usbmgrregbulkcallback_fuzzer/usbmgrregbulkcallback_fuzzer.cpp",
]
}
ohos_fuzztest("UsbMgrUnRegBulkCallbackFuzzTest") {
module_out_path = module_output_path
fuzz_config_file =
"${usb_manager_path}/test/fuzztest/usbmgrunregbulkcallback_fuzzer"
configs = [ ":module_private_config" ]
deps = [
"${usb_manager_path}/interfaces/innerkits:usbsrv_client",
"${usb_manager_path}/services:usbservice",
]
external_deps = [
"hiviewdfx_hilog_native:libhilog",
"ipc:ipc_core",
"usb_device_driver:usbd_client",
"utils_base:utils",
]
sources = [
"${usb_manager_path}/test/common/src/usb_callback_test.cpp",
"common/src/usb_common_fuzz.cpp",
"usbmgrunregbulkcallback_fuzzer/usbmgrunregbulkcallback_fuzzer.cpp",
]
}
ohos_fuzztest("UsbMgrBulkReadFuzzTest") {
module_out_path = module_output_path
fuzz_config_file = "${usb_manager_path}/test/fuzztest/usbmgrbulkread_fuzzer"
configs = [ ":module_private_config" ]
deps = [
"${usb_manager_path}/interfaces/innerkits:usbsrv_client",
"${usb_manager_path}/services:usbservice",
]
external_deps = [
"hiviewdfx_hilog_native:libhilog",
"ipc:ipc_core",
"usb_device_driver:usbd_client",
"utils_base:utils",
]
sources = [
"${usb_manager_path}/test/common/src/usb_callback_test.cpp",
"common/src/usb_common_fuzz.cpp",
"usbmgrbulkread_fuzzer/usbmgrbulkread_fuzzer.cpp",
]
}
ohos_fuzztest("UsbMgrBulkWriteFuzzTest") {
module_out_path = module_output_path
fuzz_config_file = "${usb_manager_path}/test/fuzztest/usbmgrbulkwrite_fuzzer"
configs = [ ":module_private_config" ]
deps = [
"${usb_manager_path}/interfaces/innerkits:usbsrv_client",
"${usb_manager_path}/services:usbservice",
]
external_deps = [
"hiviewdfx_hilog_native:libhilog",
"ipc:ipc_core",
"usb_device_driver:usbd_client",
"utils_base:utils",
]
sources = [
"${usb_manager_path}/test/common/src/usb_callback_test.cpp",
"common/src/usb_common_fuzz.cpp",
"usbmgrbulkwrite_fuzzer/usbmgrbulkwrite_fuzzer.cpp",
]
}
ohos_fuzztest("UsbMgrBulkCancelFuzzTest") {
module_out_path = module_output_path
fuzz_config_file = "${usb_manager_path}/test/fuzztest/usbmgrbulkcancel_fuzzer"
configs = [ ":module_private_config" ]
deps = [
"${usb_manager_path}/interfaces/innerkits:usbsrv_client",
"${usb_manager_path}/services:usbservice",
]
external_deps = [
"hiviewdfx_hilog_native:libhilog",
"ipc:ipc_core",
"usb_device_driver:usbd_client",
"utils_base:utils",
]
sources = [
"${usb_manager_path}/test/common/src/usb_callback_test.cpp",
"common/src/usb_common_fuzz.cpp",
"usbmgrbulkcancel_fuzzer/usbmgrbulkcancel_fuzzer.cpp",
]
}
group("fuzztest") {
testonly = true
deps = []
deps += [
":UsbMgrBulkCancelFuzzTest",
":UsbMgrBulkReadFuzzTest",
":UsbMgrBulkTransferFuzzTest",
":UsbMgrBulkWriteFuzzTest",
":UsbMgrClaimInterfaceFuzzTest",
":UsbMgrCloseFuzzTest",
":UsbMgrControlTransferFuzzTest",
":UsbMgrGetFileDescriptorFuzzTest",
":UsbMgrGetRawDescriptorsFuzzTest",
":UsbMgrGetSupportedModesFuzzTest",
":UsbMgrHasRightFuzzTest",
":UsbMgrPipeRequestWaitFuzzTest",
":UsbMgrRegBulkCallbackFuzzTest",
":UsbMgrReleaseInterfaceFuzzTest",
":UsbMgrRemoveRightFuzzTest",
":UsbMgrRequestFreeFuzzTest",
":UsbMgrRequestInitializeFuzzTest",
":UsbMgrRequestQueueFuzzTest",
":UsbMgrRequestRightFuzzTest",
":UsbMgrSetConfigurationFuzzTest",
":UsbMgrSetCurrentFunctionsFuzzTest",
":UsbMgrSetInterfaceFuzzTest",
":UsbMgrSetPortRoleFuzzTest",
":UsbMgrUnRegBulkCallbackFuzzTest",
":UsbMgrUsbFunctionsFromStringFuzzTest",
":UsbMgrUsbFunctionsToStringFuzzTest",
]
}
@@ -0,0 +1,14 @@
# 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
@@ -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,98 @@
/*
* 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 "usbmgrbulkcancel_fuzzer.h"
#include <array>
#include <optional>
#include "iremote_object.h"
#include "ashmem.h"
#include "usb_errors.h"
#include "usb_callback_test.h"
#include "usb_common_fuzz.h"
namespace {
const uint32_t ASHMEM_MAX_SIZE = 1024;
const uint32_t MEM_DATA = 1024 * 1024;
}
namespace OHOS {
namespace USB {
sptr<Ashmem> GetSharedMem()
{
sptr<Ashmem> asmptr = Ashmem::CreateAshmem("ttashmem001", MEM_DATA);
if (asmptr == nullptr) {
USB_HILOGE(MODULE_USB_SERVICE, "InitAshmemOne CreateAshmem failed");
return nullptr;
}
asmptr->MapReadAndWriteAshmem();
std::array<uint8_t, ASHMEM_MAX_SIZE> tdata;
tdata.fill('Y');
uint32_t offset = 0;
uint32_t tlen = 0;
while (offset < MEM_DATA) {
tlen = (MEM_DATA - offset) < ASHMEM_MAX_SIZE ? (MEM_DATA - offset) : ASHMEM_MAX_SIZE;
asmptr->WriteToAshmem(tdata.data(), tlen, offset);
offset += tlen;
}
return asmptr;
}
bool UsbMgrBulkCancelFuzzTest(const uint8_t* data, size_t /* size */)
{
auto[res, pipe, interface] = UsbMgrPrepareFuzzEnv();
if (!res) {
USB_HILOGE(MODULE_USB_SERVICE, "prepare error");
return false;
}
auto& usbSrvClient = UsbSrvClient::GetInstance();
sptr<UsbCallbackTest> cb = new UsbCallbackTest();
USBEndpoint point = interface.GetEndpoints().at(1);
auto ret = usbSrvClient.RegBulkCallback(pipe, point, cb);
if (ret != UEC_OK) {
USB_HILOGE(MODULE_USB_SERVICE, "RegBulkCallback failed ret=%{public}d", ret);
return false;
}
auto sharedMem = GetSharedMem();
if (sharedMem == nullptr) {
USB_HILOGE(MODULE_USB_SERVICE, "GetSharedMem failed ret=%{public}d", ret);
return false;
}
ret = usbSrvClient.BulkWrite(pipe, point, sharedMem);
if (ret != UEC_OK) {
USB_HILOGE(MODULE_USB_SERVICE, "BulkWrite failed ret=%{public}d", ret);
return false;
}
if (usbSrvClient.BulkCancel(reinterpret_cast<const USBDevicePipe&>(data),
reinterpret_cast<const USBEndpoint&>(data)) == UEC_OK) {
return false;
}
return true;
}
} // USB
} // OHOS
/* Fuzzer entry point */
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
{
/* Run your code on data */
OHOS::USB::UsbMgrBulkCancelFuzzTest(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 USBMGRBULKCANCEL_FUZZER_H
#define USBMGRBULKCANCEL_FUZZER_H
#define FUZZ_PROJECT_NAME "usbmgrbulkcancel_fuzzer"
#endif // USBMGRBULKCANCEL_FUZZER_H
@@ -0,0 +1,14 @@
# 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
@@ -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,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.
*/
#include "usbmgrbulkread_fuzzer.h"
#include "iremote_object.h"
#include "usb_errors.h"
#include "usb_callback_test.h"
#include "usb_common_fuzz.h"
namespace OHOS {
namespace USB {
bool UsbMgrBulkReadFuzzTest(const uint8_t* data, size_t /* size */)
{
auto[res, pipe, interface] = UsbMgrPrepareFuzzEnv();
if (!res) {
USB_HILOGE(MODULE_USB_SERVICE, "prepare error");
return false;
}
auto& usbSrvClient = UsbSrvClient::GetInstance();
sptr<UsbCallbackTest> cb = new UsbCallbackTest();
auto ret = usbSrvClient.RegBulkCallback(pipe, interface.GetEndpoints().at(1), cb);
if (ret != UEC_OK) {
USB_HILOGE(MODULE_USB_SERVICE, "RegBulkCallback failed ret=%{public}d", ret);
return false;
}
if (usbSrvClient.BulkRead(reinterpret_cast<const USBDevicePipe&>(data),
reinterpret_cast<const USBEndpoint&>(data), reinterpret_cast<sptr<Ashmem>&>(data)) == UEC_OK) {
return false;
}
return true;
}
} // USB
} // OHOS
/* Fuzzer entry point */
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
{
/* Run your code on data */
OHOS::USB::UsbMgrBulkReadFuzzTest(data, size);
return 0;
}
@@ -0,0 +1,20 @@
/*
* 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 USBMGRBULKREAD_FUZZER_H
#define USBMGRBULKREAD_FUZZER_H
#define FUZZ_PROJECT_NAME "usbmgrbulkread_fuzzer"
#endif // USBMGRBULKREAD_FUZZER_H
@@ -0,0 +1,14 @@
# 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
@@ -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,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.
*/
#include "usbmgrbulkwrite_fuzzer.h"
#include "iremote_object.h"
#include "usb_errors.h"
#include "usb_callback_test.h"
#include "usb_common_fuzz.h"
namespace OHOS {
namespace USB {
bool UsbMgrBulkWriteFuzzTest(const uint8_t* data, size_t /* size */)
{
auto[res, pipe, interface] = UsbMgrPrepareFuzzEnv();
if (!res) {
USB_HILOGE(MODULE_USB_SERVICE, "prepare error");
return false;
}
auto& usbSrvClient = UsbSrvClient::GetInstance();
sptr<UsbCallbackTest> cb = new UsbCallbackTest();
auto ret = usbSrvClient.RegBulkCallback(pipe, interface.GetEndpoints().at(1), cb);
if (ret != UEC_OK) {
USB_HILOGE(MODULE_USB_SERVICE, "RegBulkCallback failed ret=%{public}d", ret);
return false;
}
if (usbSrvClient.BulkWrite(reinterpret_cast<const USBDevicePipe&>(data),
reinterpret_cast<const USBEndpoint&>(data), reinterpret_cast<sptr<Ashmem>&>(data)) == UEC_OK) {
return false;
}
return true;
}
} // USB
} // OHOS
/* Fuzzer entry point */
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
{
/* Run your code on data */
OHOS::USB::UsbMgrBulkWriteFuzzTest(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 USBMGRBULKWRITE_FUZZER_H
#define USBMGRBULKWRITE_FUZZER_H
#define FUZZ_PROJECT_NAME "usbmgrbulkwrite_fuzzer"
#endif // USBMGRBULKWRITE_FUZZER_H
@@ -0,0 +1,14 @@
# 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
@@ -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,58 @@
/*
* 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 "usbmgrsetconfiguration_fuzzer.h"
#include "usb_srv_client.h"
#include "usb_errors.h"
namespace OHOS {
namespace USB {
bool UsbMgrSetConfigurationFuzzTest(const uint8_t* data, size_t /* size */)
{
std::vector<UsbDevice> devList;
auto &usbSrvClient = UsbSrvClient::GetInstance();
auto ret = usbSrvClient.GetDevices(devList);
if (ret != UEC_OK || devList.empty()) {
USB_HILOGE(MODULE_USB_SERVICE, "get devices failed ret=%{public}d", ret);
return false;
}
USBDevicePipe pipe;
UsbDevice device = devList.front();
usbSrvClient.RequestRight(device.GetName());
ret = usbSrvClient.OpenDevice(device, pipe);
if (ret != UEC_OK) {
USB_HILOGE(MODULE_USB_SERVICE, "open device failed ret=%{public}d", ret);
return false;
}
if (usbSrvClient.SetConfiguration(reinterpret_cast<const USBDevicePipe &>(data),
reinterpret_cast<const USBConfig &>(data)) == UEC_OK) {
return false;
}
return true;
}
} // USB
} // OHOS
/* Fuzzer entry point */
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
{
/* Run your code on data */
OHOS::USB::UsbMgrSetConfigurationFuzzTest(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 USBMGRSETCONFIGURATION_FUZZER_H
#define USBMGRSETCONFIGURATION_FUZZER_H
#define FUZZ_PROJECT_NAME "usbmgrsetconfiguration_fuzzer"
#endif // USBMGRSETCONFIGURATION_FUZZER_H
@@ -0,0 +1,14 @@
# 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
@@ -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,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.
*/
#include "usbmgrsetcurrentfunctions_fuzzer.h"
#include "usb_srv_client.h"
#include "usb_errors.h"
namespace {
const int32_t MAX_FUNC_NUM = 6;
}
namespace OHOS {
namespace USB {
bool UsbMgrSetCurrentFunctionsFuzzTest(const uint8_t* data, size_t /* size */)
{
auto &usbSrvClient = UsbSrvClient::GetInstance();
int32_t func = reinterpret_cast<int32_t>(data);
if (func <= MAX_FUNC_NUM) {
func += MAX_FUNC_NUM;
}
if (usbSrvClient.SetCurrentFunctions(func) == UEC_OK) {
return false;
}
return true;
}
} // USB
} // OHOS
/* Fuzzer entry point */
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
{
/* Run your code on data */
OHOS::USB::UsbMgrSetCurrentFunctionsFuzzTest(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 USBMGRSETCURRENTFUNCTIONS_FUZZER_H
#define USBMGRSETCURRENTFUNCTIONS_FUZZER_H
#define FUZZ_PROJECT_NAME "usbmgrsetcurrentfunctions_fuzzer"
#endif // USBMGRSETCURRENTFUNCTIONS_FUZZER_H
@@ -0,0 +1,14 @@
# 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
@@ -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,65 @@
/*
* 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 "usbmgrsetinterface_fuzzer.h"
#include "usb_srv_client.h"
#include "usb_errors.h"
namespace OHOS {
namespace USB {
bool UsbMgrSetInterfaceFuzzTest(const uint8_t* data, size_t /* size */)
{
std::vector<UsbDevice> devList;
auto &usbSrvClient = UsbSrvClient::GetInstance();
auto ret = usbSrvClient.GetDevices(devList);
if (ret != UEC_OK || devList.empty()) {
USB_HILOGE(MODULE_USB_SERVICE, "get devices failed ret=%{public}d", ret);
return false;
}
USBDevicePipe pipe;
UsbDevice device = devList.front();
usbSrvClient.RequestRight(device.GetName());
ret = usbSrvClient.OpenDevice(device, pipe);
if (ret != UEC_OK) {
USB_HILOGE(MODULE_USB_SERVICE, "open device failed ret=%{public}d", ret);
return false;
}
UsbInterface interface = devList.front().GetConfigs().front().GetInterfaces().front();
ret = usbSrvClient.ClaimInterface(pipe, interface, true);
if (ret != UEC_OK) {
USB_HILOGE(MODULE_USB_SERVICE, "ClaimInterface failed ret=%{public}d", ret);
return false;
}
if (usbSrvClient.SetInterface(reinterpret_cast<const USBDevicePipe&>(data),
reinterpret_cast<const UsbInterface&>(data)) == UEC_OK) {
return false;
}
return true;
}
} // USB
} // OHOS
/* Fuzzer entry point */
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
{
/* Run your code on data */
OHOS::USB::UsbMgrSetInterfaceFuzzTest(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 USBMGRSETINTERFACE_FUZZER_H
#define USBMGRSETINTERFACE_FUZZER_H
#define FUZZ_PROJECT_NAME "usbmgrsetinterface_fuzzer"
#endif // USBMGRSETINTERFACE_FUZZER_H
@@ -0,0 +1,14 @@
# 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
@@ -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,42 @@
/*
* 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 "usbmgrsetportrole_fuzzer.h"
#include "usb_srv_client.h"
#include "usb_errors.h"
namespace OHOS {
namespace USB {
bool UsbMgrSetPortRoleFuzzTest(const uint8_t* data, size_t /* size */)
{
auto &usbSrvClient = UsbSrvClient::GetInstance();
if (usbSrvClient.SetPortRole(reinterpret_cast<int32_t>(data), reinterpret_cast<int32_t>(data),
reinterpret_cast<int32_t>(data)) == UEC_OK) {
return false;
}
return true;
}
} // USB
} // OHOS
/* Fuzzer entry point */
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
{
/* Run your code on data */
OHOS::USB::UsbMgrSetPortRoleFuzzTest(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 USBMGRSETPORTROLE_FUZZER_H
#define USBMGRSETPORTROLE_FUZZER_H
#define FUZZ_PROJECT_NAME "usbmgrsetportrole_fuzzer"
#endif // USBMGRSETPORTROLE_FUZZER_H