!59 add fuzz test cases

Merge pull request !59 from 吴成文/master
This commit is contained in:
openharmony_ci
2022-05-06 07:51:05 +00:00
committed by Gitee
42 changed files with 1173 additions and 57 deletions
@@ -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 "usbmgrgetfiledescriptor_fuzzer.h"
#include "usb_srv_client.h"
#include "usb_errors.h"
namespace OHOS {
namespace USB {
bool UsbMgrGetFileDescriptorFuzzTest(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;
}
int32_t fd;
if (usbSrvClient.GetFileDescriptor(reinterpret_cast<const USBDevicePipe&>(data), fd) == 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::UsbMgrGetFileDescriptorFuzzTest(data, size);
return 0;
}
@@ -1,26 +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.
*/
#include "usb_callback_test.h"
int32_t UsbCallbackTest::OnBulkWriteCallback(int32_t status, int32_t actLength)
{
return 0;
}
int32_t UsbCallbackTest::OnBulkReadCallback(int32_t status, int32_t actLength)
{
return 0;
}
/*
* 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 USBMGRGETFILEDESCRIPTOR_FUZZER_H
#define USBMGRGETFILEDESCRIPTOR_FUZZER_H
#define FUZZ_PROJECT_NAME "usbmgrgetfiledescriptor_fuzzer"
#endif // USBMGRGETFILEDESCRIPTOR_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 "usbmgrgetrawdescriptors_fuzzer.h"
#include "usb_srv_client.h"
#include "usb_errors.h"
namespace OHOS {
namespace USB {
bool UsbMgrGetRawDescriptorsFuzzTest(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;
}
std::vector<uint8_t> buf;
if (usbSrvClient.GetRawDescriptors(reinterpret_cast<const USBDevicePipe&>(data), buf) == 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::UsbMgrGetRawDescriptorsFuzzTest(data, size);
return 0;
}
@@ -1,27 +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 USB_CALLBACK_TEST_H
#define USB_CALLBACK_TEST_H
#include "usbd_bulk_callback.h"
class UsbCallbackTest : public OHOS::USB::UsbdBulkCallBack {
public:
int32_t OnBulkWriteCallback(int32_t status, int32_t actLength);
int32_t OnBulkReadCallback(int32_t status, int32_t actLength);
};
#endif
/*
* 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 USBMGRGETRAWDESCRIPTORS_FUZZER_H
#define USBMGRGETRAWDESCRIPTORS_FUZZER_H
#define FUZZ_PROJECT_NAME "usbmgrgetrawdescriptors_fuzzer"
#endif // USBMGRGETRAWDESCRIPTORS_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,43 @@
/*
* 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 "usbmgrgetsupportedmodes_fuzzer.h"
#include "usb_srv_client.h"
#include "usb_errors.h"
namespace OHOS {
namespace USB {
bool UsbMgrGetSupportedModesFuzzTest(const uint8_t* data, size_t /* size */)
{
auto &usbSrvClient = UsbSrvClient::GetInstance();
int32_t supportModes = 0;
int32_t ret = usbSrvClient.GetSupportedModes(reinterpret_cast<int32_t>(data), supportModes);
if (ret == UEC_OK) {
return false;
}
return true;
}
}
}
/* Fuzzer entry point */
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
{
/* Run your code on data */
OHOS::USB::UsbMgrGetSupportedModesFuzzTest(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 USBMGRGETSUPPORTEDMODES_FUZZER_H
#define USBMGRGETSUPPORTEDMODES_FUZZER_H
#define FUZZ_PROJECT_NAME "usbmgrgetsupportedmodes_fuzzer"
#endif // USBMGRGETSUPPORTEDMODES_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,51 @@
/*
* 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 "usbmgrregbulkcallback_fuzzer.h"
#include "iremote_object.h"
#include "usb_srv_client.h"
#include "usb_errors.h"
#include "usb_common_fuzz.h"
namespace OHOS {
namespace USB {
bool UsbMgrRegBulkCallbackFuzzTest(const uint8_t* data, size_t /* size */)
{
auto[res, pipe, interface] = UsbMgrPrepareFuzzEnv();
(void)pipe;
(void)interface;
if (!res) {
USB_HILOGE(MODULE_USB_SERVICE, "prepare error");
return false;
}
if (UsbSrvClient::GetInstance().RegBulkCallback(reinterpret_cast<const USBDevicePipe&>(data),
reinterpret_cast<const USBEndpoint&>(data), reinterpret_cast<const sptr<IRemoteObject>&>(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::UsbMgrRegBulkCallbackFuzzTest(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 USBMGRREGBULKCALLBACK_FUZZER_H
#define USBMGRREGBULKCALLBACK_FUZZER_H
#define FUZZ_PROJECT_NAME "usbmgrregbulkcallback_fuzzer"
#endif // USBMGRREGBULKCALLBACK_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,66 @@
/*
* 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 "usbmgrreleaseinterface_fuzzer.h"
#include "usb_srv_client.h"
#include "usb_errors.h"
namespace OHOS {
namespace USB {
bool UsbMgrReleaseInterfaceFuzzTest(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;
}
ret = usbSrvClient.ReleaseInterface(reinterpret_cast<const USBDevicePipe&>(data),
reinterpret_cast<const UsbInterface&>(data));
if (ret == 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::UsbMgrReleaseInterfaceFuzzTest(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 USBMGRRELEASEINTERFACE_FUZZER_H
#define USBMGRRELEASEINTERFACE_FUZZER_H
#define FUZZ_PROJECT_NAME "usbmgrreleaseinterface_fuzzer"
#endif // USBMGRRELEASEINTERFACE_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,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.
*/
#include "usbmgrremoveright_fuzzer.h"
#include "usb_srv_client.h"
#include "usb_errors.h"
namespace OHOS {
namespace USB {
bool UsbMgrRemoveRightFuzzTest(const uint8_t* data, size_t /* size */)
{
auto &usbSrvClient = UsbSrvClient::GetInstance();
std::vector<UsbDevice> devList;
auto ret = usbSrvClient.GetDevices(devList);
if (ret != UEC_OK || devList.empty()) {
USB_HILOGE(MODULE_USB_SERVICE, "get devices failed");
return false;
}
ret = usbSrvClient.RequestRight(devList[0].GetName());
if (ret != UEC_OK) {
USB_HILOGE(MODULE_USB_SERVICE, "request right failed");
return false;
}
if (!usbSrvClient.HasRight(devList[0].GetName())) {
USB_HILOGE(MODULE_USB_SERVICE, "device right error");
return false;
}
if (usbSrvClient.RemoveRight(std::string((const char*)data)) == UEC_OK) {
return false;
}
return true;
}
}
}
/* Fuzzer entry point */
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
{
/* Run your code on data */
OHOS::USB::UsbMgrRemoveRightFuzzTest(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 USBMGRREMOVERIGHT_FUZZER_H
#define USBMGRREMOVERIGHT_FUZZER_H
#define FUZZ_PROJECT_NAME "usbmgrremoveright_fuzzer"
#endif // USBMGRREMOVERIGHT_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,64 @@
/*
* 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 "usbmgrrequestfree_fuzzer.h"
#include "usb_srv_client.h"
#include "usb_errors.h"
namespace OHOS {
namespace USB {
bool UsbMgrRequestFreeFuzzTest(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.RequestFree(reinterpret_cast<const UsbRequest&>(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::UsbMgrRequestFreeFuzzTest(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 USBMGRREQUESTFREE_FUZZER_H
#define USBMGRREQUESTFREE_FUZZER_H
#define FUZZ_PROJECT_NAME "usbmgrrequestfree_fuzzer"
#endif // USBMGRREQUESTFREE_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 "usbmgrrequestinitialize_fuzzer.h"
#include "usb_srv_client.h"
#include "usb_errors.h"
namespace OHOS {
namespace USB {
bool UsbMgrRequestInitializeFuzzTest(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.RequestInitialize(reinterpret_cast<const UsbRequest&>(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::UsbMgrRequestInitializeFuzzTest(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 USBMGRREQUESTINITIALIZE_FUZZER_H
#define USBMGRREQUESTINITIALIZE_FUZZER_H
#define FUZZ_PROJECT_NAME "usbmgrrequestinitialize_fuzzer"
#endif // USBMGRREQUESTINITIALIZE_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,64 @@
/*
* 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 "usbmgrrequestqueue_fuzzer.h"
#include "usb_srv_client.h"
#include "usb_errors.h"
namespace OHOS {
namespace USB {
bool UsbMgrRequestQueueFuzzTest(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.RequestQueue(reinterpret_cast<const UsbRequest&>(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::UsbMgrRequestQueueFuzzTest(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 USBMGRREQUESTQUEUE_FUZZER_H
#define USBMGRREQUESTQUEUE_FUZZER_H
#define FUZZ_PROJECT_NAME "usbmgrrequestqueue_fuzzer"
#endif // USBMGRREQUESTQUEUE_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,41 @@
/*
* 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 "usbmgrrequestright_fuzzer.h"
#include "usb_srv_client.h"
#include "usb_errors.h"
namespace OHOS {
namespace USB {
bool UsbMgrRequestRightFuzzTest(const uint8_t* data, size_t /* size */)
{
auto &usbSrvClient = UsbSrvClient::GetInstance();
if (usbSrvClient.RequestRight(std::string((const char*)data)) == UEC_OK) {
return false;
}
return true;
}
}
}
/* Fuzzer entry point */
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
{
/* Run your code on data */
OHOS::USB::UsbMgrRequestRightFuzzTest(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 USBMGRREQUESTRIGHT_FUZZER_H
#define USBMGRREQUESTRIGHT_FUZZER_H
#define FUZZ_PROJECT_NAME "usbmgrrequestright_fuzzer"
#endif // USBMGRREQUESTRIGHT_FUZZER_H
+1 -1
View File
@@ -16,5 +16,5 @@ import("//build/test.gni")
group("usb_unittest_test") {
testonly = true
deps = [ "service_unittest:unittest" ]
deps = []
}
+11 -3
View File
@@ -19,7 +19,10 @@ module_output_path = "${usb_manager_part_name}/usb_unittest_test"
config("module_private_config") {
visibility = [ ":*" ]
include_dirs = [ "include" ]
include_dirs = [
"include",
"${usb_manager_path}/test/common/include/",
]
}
ohos_unittest("test_usbdevicepipe") {
@@ -54,8 +57,8 @@ ohos_unittest("test_usbdevicepipe") {
ohos_unittest("test_bulkcallback") {
module_out_path = module_output_path
sources = [
"${usb_manager_path}/test/common/src/usb_callback_test.cpp",
"src/usb_bulkcallback_test.cpp",
"src/usb_callback_test.cpp",
]
configs = [
@@ -143,5 +146,10 @@ ohos_unittest("test_usbcore") {
group("unittest") {
testonly = true
deps = []
deps = [
":test_bulkcallback",
":test_usbcore",
":test_usbdevicepipe",
":test_usbrequest",
]
}