From b0c7a06d36457e0ef65faddf7a753e4ae42a83c5 Mon Sep 17 00:00:00 2001 From: wu-chengwen Date: Fri, 6 May 2022 10:50:46 +0800 Subject: [PATCH] fix(usb):add usb fuzz test cases Signed-off-by: wu-chengwen --- .../corpus/init | 14 ++++ .../project.xml | 25 +++++++ .../usbmgrgetfiledescriptor_fuzzer.cpp | 58 ++++++++++++++++ .../usbmgrgetfiledescriptor_fuzzer.h} | 47 ++++++------- .../corpus/init | 14 ++++ .../project.xml | 25 +++++++ .../usbmgrgetrawdescriptors_fuzzer.cpp | 58 ++++++++++++++++ .../usbmgrgetrawdescriptors_fuzzer.h} | 48 ++++++-------- .../corpus/init | 14 ++++ .../project.xml | 25 +++++++ .../usbmgrgetsupportedmodes_fuzzer.cpp | 43 ++++++++++++ .../usbmgrgetsupportedmodes_fuzzer.h | 21 ++++++ .../usbmgrregbulkcallback_fuzzer/corpus/init | 14 ++++ .../usbmgrregbulkcallback_fuzzer/project.xml | 25 +++++++ .../usbmgrregbulkcallback_fuzzer.cpp | 51 ++++++++++++++ .../usbmgrregbulkcallback_fuzzer.h | 21 ++++++ .../usbmgrreleaseinterface_fuzzer/corpus/init | 14 ++++ .../usbmgrreleaseinterface_fuzzer/project.xml | 25 +++++++ .../usbmgrreleaseinterface_fuzzer.cpp | 66 +++++++++++++++++++ .../usbmgrreleaseinterface_fuzzer.h | 21 ++++++ .../usbmgrremoveright_fuzzer/corpus/init | 14 ++++ .../usbmgrremoveright_fuzzer/project.xml | 25 +++++++ .../usbmgrremoveright_fuzzer.cpp | 59 +++++++++++++++++ .../usbmgrremoveright_fuzzer.h | 21 ++++++ .../usbmgrrequestfree_fuzzer/corpus/init | 14 ++++ .../usbmgrrequestfree_fuzzer/project.xml | 25 +++++++ .../usbmgrrequestfree_fuzzer.cpp | 64 ++++++++++++++++++ .../usbmgrrequestfree_fuzzer.h | 21 ++++++ .../corpus/init | 14 ++++ .../project.xml | 25 +++++++ .../usbmgrrequestinitialize_fuzzer.cpp | 57 ++++++++++++++++ .../usbmgrrequestinitialize_fuzzer.h | 21 ++++++ .../usbmgrrequestqueue_fuzzer/corpus/init | 14 ++++ .../usbmgrrequestqueue_fuzzer/project.xml | 25 +++++++ .../usbmgrrequestqueue_fuzzer.cpp | 64 ++++++++++++++++++ .../usbmgrrequestqueue_fuzzer.h | 21 ++++++ .../usbmgrrequestright_fuzzer/corpus/init | 14 ++++ .../usbmgrrequestright_fuzzer/project.xml | 25 +++++++ .../usbmgrrequestright_fuzzer.cpp | 41 ++++++++++++ .../usbmgrrequestright_fuzzer.h | 21 ++++++ test/native/BUILD.gn | 2 +- test/native/service_unittest/BUILD.gn | 14 +++- 42 files changed, 1173 insertions(+), 57 deletions(-) create mode 100644 test/fuzztest/usbmgrgetfiledescriptor_fuzzer/corpus/init create mode 100644 test/fuzztest/usbmgrgetfiledescriptor_fuzzer/project.xml create mode 100644 test/fuzztest/usbmgrgetfiledescriptor_fuzzer/usbmgrgetfiledescriptor_fuzzer.cpp rename test/{native/service_unittest/src/usb_callback_test.cpp => fuzztest/usbmgrgetfiledescriptor_fuzzer/usbmgrgetfiledescriptor_fuzzer.h} (70%) create mode 100644 test/fuzztest/usbmgrgetrawdescriptors_fuzzer/corpus/init create mode 100644 test/fuzztest/usbmgrgetrawdescriptors_fuzzer/project.xml create mode 100644 test/fuzztest/usbmgrgetrawdescriptors_fuzzer/usbmgrgetrawdescriptors_fuzzer.cpp rename test/{native/service_unittest/include/usb_callback_test.h => fuzztest/usbmgrgetrawdescriptors_fuzzer/usbmgrgetrawdescriptors_fuzzer.h} (65%) mode change 100755 => 100644 create mode 100644 test/fuzztest/usbmgrgetsupportedmodes_fuzzer/corpus/init create mode 100644 test/fuzztest/usbmgrgetsupportedmodes_fuzzer/project.xml create mode 100644 test/fuzztest/usbmgrgetsupportedmodes_fuzzer/usbmgrgetsupportedmodes_fuzzer.cpp create mode 100644 test/fuzztest/usbmgrgetsupportedmodes_fuzzer/usbmgrgetsupportedmodes_fuzzer.h create mode 100644 test/fuzztest/usbmgrregbulkcallback_fuzzer/corpus/init create mode 100644 test/fuzztest/usbmgrregbulkcallback_fuzzer/project.xml create mode 100644 test/fuzztest/usbmgrregbulkcallback_fuzzer/usbmgrregbulkcallback_fuzzer.cpp create mode 100644 test/fuzztest/usbmgrregbulkcallback_fuzzer/usbmgrregbulkcallback_fuzzer.h create mode 100644 test/fuzztest/usbmgrreleaseinterface_fuzzer/corpus/init create mode 100644 test/fuzztest/usbmgrreleaseinterface_fuzzer/project.xml create mode 100644 test/fuzztest/usbmgrreleaseinterface_fuzzer/usbmgrreleaseinterface_fuzzer.cpp create mode 100644 test/fuzztest/usbmgrreleaseinterface_fuzzer/usbmgrreleaseinterface_fuzzer.h create mode 100644 test/fuzztest/usbmgrremoveright_fuzzer/corpus/init create mode 100644 test/fuzztest/usbmgrremoveright_fuzzer/project.xml create mode 100644 test/fuzztest/usbmgrremoveright_fuzzer/usbmgrremoveright_fuzzer.cpp create mode 100644 test/fuzztest/usbmgrremoveright_fuzzer/usbmgrremoveright_fuzzer.h create mode 100644 test/fuzztest/usbmgrrequestfree_fuzzer/corpus/init create mode 100644 test/fuzztest/usbmgrrequestfree_fuzzer/project.xml create mode 100644 test/fuzztest/usbmgrrequestfree_fuzzer/usbmgrrequestfree_fuzzer.cpp create mode 100644 test/fuzztest/usbmgrrequestfree_fuzzer/usbmgrrequestfree_fuzzer.h create mode 100644 test/fuzztest/usbmgrrequestinitialize_fuzzer/corpus/init create mode 100644 test/fuzztest/usbmgrrequestinitialize_fuzzer/project.xml create mode 100644 test/fuzztest/usbmgrrequestinitialize_fuzzer/usbmgrrequestinitialize_fuzzer.cpp create mode 100644 test/fuzztest/usbmgrrequestinitialize_fuzzer/usbmgrrequestinitialize_fuzzer.h create mode 100644 test/fuzztest/usbmgrrequestqueue_fuzzer/corpus/init create mode 100644 test/fuzztest/usbmgrrequestqueue_fuzzer/project.xml create mode 100644 test/fuzztest/usbmgrrequestqueue_fuzzer/usbmgrrequestqueue_fuzzer.cpp create mode 100644 test/fuzztest/usbmgrrequestqueue_fuzzer/usbmgrrequestqueue_fuzzer.h create mode 100644 test/fuzztest/usbmgrrequestright_fuzzer/corpus/init create mode 100644 test/fuzztest/usbmgrrequestright_fuzzer/project.xml create mode 100644 test/fuzztest/usbmgrrequestright_fuzzer/usbmgrrequestright_fuzzer.cpp create mode 100644 test/fuzztest/usbmgrrequestright_fuzzer/usbmgrrequestright_fuzzer.h diff --git a/test/fuzztest/usbmgrgetfiledescriptor_fuzzer/corpus/init b/test/fuzztest/usbmgrgetfiledescriptor_fuzzer/corpus/init new file mode 100644 index 0000000..bc977bd --- /dev/null +++ b/test/fuzztest/usbmgrgetfiledescriptor_fuzzer/corpus/init @@ -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 \ No newline at end of file diff --git a/test/fuzztest/usbmgrgetfiledescriptor_fuzzer/project.xml b/test/fuzztest/usbmgrgetfiledescriptor_fuzzer/project.xml new file mode 100644 index 0000000..6e8ad2c --- /dev/null +++ b/test/fuzztest/usbmgrgetfiledescriptor_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/usbmgrgetfiledescriptor_fuzzer/usbmgrgetfiledescriptor_fuzzer.cpp b/test/fuzztest/usbmgrgetfiledescriptor_fuzzer/usbmgrgetfiledescriptor_fuzzer.cpp new file mode 100644 index 0000000..12a5451 --- /dev/null +++ b/test/fuzztest/usbmgrgetfiledescriptor_fuzzer/usbmgrgetfiledescriptor_fuzzer.cpp @@ -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 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(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; +} + diff --git a/test/native/service_unittest/src/usb_callback_test.cpp b/test/fuzztest/usbmgrgetfiledescriptor_fuzzer/usbmgrgetfiledescriptor_fuzzer.h similarity index 70% rename from test/native/service_unittest/src/usb_callback_test.cpp rename to test/fuzztest/usbmgrgetfiledescriptor_fuzzer/usbmgrgetfiledescriptor_fuzzer.h index 9449224..9f69202 100644 --- a/test/native/service_unittest/src/usb_callback_test.cpp +++ b/test/fuzztest/usbmgrgetfiledescriptor_fuzzer/usbmgrgetfiledescriptor_fuzzer.h @@ -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; -} \ No newline at end of file +/* + * 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 diff --git a/test/fuzztest/usbmgrgetrawdescriptors_fuzzer/corpus/init b/test/fuzztest/usbmgrgetrawdescriptors_fuzzer/corpus/init new file mode 100644 index 0000000..bc977bd --- /dev/null +++ b/test/fuzztest/usbmgrgetrawdescriptors_fuzzer/corpus/init @@ -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 \ No newline at end of file diff --git a/test/fuzztest/usbmgrgetrawdescriptors_fuzzer/project.xml b/test/fuzztest/usbmgrgetrawdescriptors_fuzzer/project.xml new file mode 100644 index 0000000..6e8ad2c --- /dev/null +++ b/test/fuzztest/usbmgrgetrawdescriptors_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/usbmgrgetrawdescriptors_fuzzer/usbmgrgetrawdescriptors_fuzzer.cpp b/test/fuzztest/usbmgrgetrawdescriptors_fuzzer/usbmgrgetrawdescriptors_fuzzer.cpp new file mode 100644 index 0000000..d880248 --- /dev/null +++ b/test/fuzztest/usbmgrgetrawdescriptors_fuzzer/usbmgrgetrawdescriptors_fuzzer.cpp @@ -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 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 buf; + if (usbSrvClient.GetRawDescriptors(reinterpret_cast(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; +} + diff --git a/test/native/service_unittest/include/usb_callback_test.h b/test/fuzztest/usbmgrgetrawdescriptors_fuzzer/usbmgrgetrawdescriptors_fuzzer.h old mode 100755 new mode 100644 similarity index 65% rename from test/native/service_unittest/include/usb_callback_test.h rename to test/fuzztest/usbmgrgetrawdescriptors_fuzzer/usbmgrgetrawdescriptors_fuzzer.h index 9f951f4..0ce3f32 --- a/test/native/service_unittest/include/usb_callback_test.h +++ b/test/fuzztest/usbmgrgetrawdescriptors_fuzzer/usbmgrgetrawdescriptors_fuzzer.h @@ -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 \ No newline at end of file +/* + * 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 diff --git a/test/fuzztest/usbmgrgetsupportedmodes_fuzzer/corpus/init b/test/fuzztest/usbmgrgetsupportedmodes_fuzzer/corpus/init new file mode 100644 index 0000000..bc977bd --- /dev/null +++ b/test/fuzztest/usbmgrgetsupportedmodes_fuzzer/corpus/init @@ -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 \ No newline at end of file diff --git a/test/fuzztest/usbmgrgetsupportedmodes_fuzzer/project.xml b/test/fuzztest/usbmgrgetsupportedmodes_fuzzer/project.xml new file mode 100644 index 0000000..6e8ad2c --- /dev/null +++ b/test/fuzztest/usbmgrgetsupportedmodes_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/usbmgrgetsupportedmodes_fuzzer/usbmgrgetsupportedmodes_fuzzer.cpp b/test/fuzztest/usbmgrgetsupportedmodes_fuzzer/usbmgrgetsupportedmodes_fuzzer.cpp new file mode 100644 index 0000000..2246352 --- /dev/null +++ b/test/fuzztest/usbmgrgetsupportedmodes_fuzzer/usbmgrgetsupportedmodes_fuzzer.cpp @@ -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(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; +} + diff --git a/test/fuzztest/usbmgrgetsupportedmodes_fuzzer/usbmgrgetsupportedmodes_fuzzer.h b/test/fuzztest/usbmgrgetsupportedmodes_fuzzer/usbmgrgetsupportedmodes_fuzzer.h new file mode 100644 index 0000000..a703b21 --- /dev/null +++ b/test/fuzztest/usbmgrgetsupportedmodes_fuzzer/usbmgrgetsupportedmodes_fuzzer.h @@ -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 diff --git a/test/fuzztest/usbmgrregbulkcallback_fuzzer/corpus/init b/test/fuzztest/usbmgrregbulkcallback_fuzzer/corpus/init new file mode 100644 index 0000000..bc977bd --- /dev/null +++ b/test/fuzztest/usbmgrregbulkcallback_fuzzer/corpus/init @@ -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 \ No newline at end of file diff --git a/test/fuzztest/usbmgrregbulkcallback_fuzzer/project.xml b/test/fuzztest/usbmgrregbulkcallback_fuzzer/project.xml new file mode 100644 index 0000000..6e8ad2c --- /dev/null +++ b/test/fuzztest/usbmgrregbulkcallback_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/usbmgrregbulkcallback_fuzzer/usbmgrregbulkcallback_fuzzer.cpp b/test/fuzztest/usbmgrregbulkcallback_fuzzer/usbmgrregbulkcallback_fuzzer.cpp new file mode 100644 index 0000000..2dbc2b8 --- /dev/null +++ b/test/fuzztest/usbmgrregbulkcallback_fuzzer/usbmgrregbulkcallback_fuzzer.cpp @@ -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(data), + reinterpret_cast(data), reinterpret_cast&>(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; +} + diff --git a/test/fuzztest/usbmgrregbulkcallback_fuzzer/usbmgrregbulkcallback_fuzzer.h b/test/fuzztest/usbmgrregbulkcallback_fuzzer/usbmgrregbulkcallback_fuzzer.h new file mode 100644 index 0000000..26d0bb6 --- /dev/null +++ b/test/fuzztest/usbmgrregbulkcallback_fuzzer/usbmgrregbulkcallback_fuzzer.h @@ -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 diff --git a/test/fuzztest/usbmgrreleaseinterface_fuzzer/corpus/init b/test/fuzztest/usbmgrreleaseinterface_fuzzer/corpus/init new file mode 100644 index 0000000..bc977bd --- /dev/null +++ b/test/fuzztest/usbmgrreleaseinterface_fuzzer/corpus/init @@ -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 \ No newline at end of file diff --git a/test/fuzztest/usbmgrreleaseinterface_fuzzer/project.xml b/test/fuzztest/usbmgrreleaseinterface_fuzzer/project.xml new file mode 100644 index 0000000..6e8ad2c --- /dev/null +++ b/test/fuzztest/usbmgrreleaseinterface_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/usbmgrreleaseinterface_fuzzer/usbmgrreleaseinterface_fuzzer.cpp b/test/fuzztest/usbmgrreleaseinterface_fuzzer/usbmgrreleaseinterface_fuzzer.cpp new file mode 100644 index 0000000..56eac6f --- /dev/null +++ b/test/fuzztest/usbmgrreleaseinterface_fuzzer/usbmgrreleaseinterface_fuzzer.cpp @@ -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 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(data), + reinterpret_cast(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; +} + diff --git a/test/fuzztest/usbmgrreleaseinterface_fuzzer/usbmgrreleaseinterface_fuzzer.h b/test/fuzztest/usbmgrreleaseinterface_fuzzer/usbmgrreleaseinterface_fuzzer.h new file mode 100644 index 0000000..29cd9bb --- /dev/null +++ b/test/fuzztest/usbmgrreleaseinterface_fuzzer/usbmgrreleaseinterface_fuzzer.h @@ -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 diff --git a/test/fuzztest/usbmgrremoveright_fuzzer/corpus/init b/test/fuzztest/usbmgrremoveright_fuzzer/corpus/init new file mode 100644 index 0000000..bc977bd --- /dev/null +++ b/test/fuzztest/usbmgrremoveright_fuzzer/corpus/init @@ -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 \ No newline at end of file diff --git a/test/fuzztest/usbmgrremoveright_fuzzer/project.xml b/test/fuzztest/usbmgrremoveright_fuzzer/project.xml new file mode 100644 index 0000000..6e8ad2c --- /dev/null +++ b/test/fuzztest/usbmgrremoveright_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/usbmgrremoveright_fuzzer/usbmgrremoveright_fuzzer.cpp b/test/fuzztest/usbmgrremoveright_fuzzer/usbmgrremoveright_fuzzer.cpp new file mode 100644 index 0000000..69e5b9e --- /dev/null +++ b/test/fuzztest/usbmgrremoveright_fuzzer/usbmgrremoveright_fuzzer.cpp @@ -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 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; +} + diff --git a/test/fuzztest/usbmgrremoveright_fuzzer/usbmgrremoveright_fuzzer.h b/test/fuzztest/usbmgrremoveright_fuzzer/usbmgrremoveright_fuzzer.h new file mode 100644 index 0000000..57a4f55 --- /dev/null +++ b/test/fuzztest/usbmgrremoveright_fuzzer/usbmgrremoveright_fuzzer.h @@ -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 diff --git a/test/fuzztest/usbmgrrequestfree_fuzzer/corpus/init b/test/fuzztest/usbmgrrequestfree_fuzzer/corpus/init new file mode 100644 index 0000000..bc977bd --- /dev/null +++ b/test/fuzztest/usbmgrrequestfree_fuzzer/corpus/init @@ -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 \ No newline at end of file diff --git a/test/fuzztest/usbmgrrequestfree_fuzzer/project.xml b/test/fuzztest/usbmgrrequestfree_fuzzer/project.xml new file mode 100644 index 0000000..6e8ad2c --- /dev/null +++ b/test/fuzztest/usbmgrrequestfree_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/usbmgrrequestfree_fuzzer/usbmgrrequestfree_fuzzer.cpp b/test/fuzztest/usbmgrrequestfree_fuzzer/usbmgrrequestfree_fuzzer.cpp new file mode 100644 index 0000000..320fe70 --- /dev/null +++ b/test/fuzztest/usbmgrrequestfree_fuzzer/usbmgrrequestfree_fuzzer.cpp @@ -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 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(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; +} + diff --git a/test/fuzztest/usbmgrrequestfree_fuzzer/usbmgrrequestfree_fuzzer.h b/test/fuzztest/usbmgrrequestfree_fuzzer/usbmgrrequestfree_fuzzer.h new file mode 100644 index 0000000..7a4775a --- /dev/null +++ b/test/fuzztest/usbmgrrequestfree_fuzzer/usbmgrrequestfree_fuzzer.h @@ -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 diff --git a/test/fuzztest/usbmgrrequestinitialize_fuzzer/corpus/init b/test/fuzztest/usbmgrrequestinitialize_fuzzer/corpus/init new file mode 100644 index 0000000..bc977bd --- /dev/null +++ b/test/fuzztest/usbmgrrequestinitialize_fuzzer/corpus/init @@ -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 \ No newline at end of file diff --git a/test/fuzztest/usbmgrrequestinitialize_fuzzer/project.xml b/test/fuzztest/usbmgrrequestinitialize_fuzzer/project.xml new file mode 100644 index 0000000..6e8ad2c --- /dev/null +++ b/test/fuzztest/usbmgrrequestinitialize_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/usbmgrrequestinitialize_fuzzer/usbmgrrequestinitialize_fuzzer.cpp b/test/fuzztest/usbmgrrequestinitialize_fuzzer/usbmgrrequestinitialize_fuzzer.cpp new file mode 100644 index 0000000..06df22f --- /dev/null +++ b/test/fuzztest/usbmgrrequestinitialize_fuzzer/usbmgrrequestinitialize_fuzzer.cpp @@ -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 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(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; +} + diff --git a/test/fuzztest/usbmgrrequestinitialize_fuzzer/usbmgrrequestinitialize_fuzzer.h b/test/fuzztest/usbmgrrequestinitialize_fuzzer/usbmgrrequestinitialize_fuzzer.h new file mode 100644 index 0000000..1df5c05 --- /dev/null +++ b/test/fuzztest/usbmgrrequestinitialize_fuzzer/usbmgrrequestinitialize_fuzzer.h @@ -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 diff --git a/test/fuzztest/usbmgrrequestqueue_fuzzer/corpus/init b/test/fuzztest/usbmgrrequestqueue_fuzzer/corpus/init new file mode 100644 index 0000000..bc977bd --- /dev/null +++ b/test/fuzztest/usbmgrrequestqueue_fuzzer/corpus/init @@ -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 \ No newline at end of file diff --git a/test/fuzztest/usbmgrrequestqueue_fuzzer/project.xml b/test/fuzztest/usbmgrrequestqueue_fuzzer/project.xml new file mode 100644 index 0000000..6e8ad2c --- /dev/null +++ b/test/fuzztest/usbmgrrequestqueue_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/usbmgrrequestqueue_fuzzer/usbmgrrequestqueue_fuzzer.cpp b/test/fuzztest/usbmgrrequestqueue_fuzzer/usbmgrrequestqueue_fuzzer.cpp new file mode 100644 index 0000000..69e4088 --- /dev/null +++ b/test/fuzztest/usbmgrrequestqueue_fuzzer/usbmgrrequestqueue_fuzzer.cpp @@ -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 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(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; +} + diff --git a/test/fuzztest/usbmgrrequestqueue_fuzzer/usbmgrrequestqueue_fuzzer.h b/test/fuzztest/usbmgrrequestqueue_fuzzer/usbmgrrequestqueue_fuzzer.h new file mode 100644 index 0000000..551ee48 --- /dev/null +++ b/test/fuzztest/usbmgrrequestqueue_fuzzer/usbmgrrequestqueue_fuzzer.h @@ -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 diff --git a/test/fuzztest/usbmgrrequestright_fuzzer/corpus/init b/test/fuzztest/usbmgrrequestright_fuzzer/corpus/init new file mode 100644 index 0000000..bc977bd --- /dev/null +++ b/test/fuzztest/usbmgrrequestright_fuzzer/corpus/init @@ -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 \ No newline at end of file diff --git a/test/fuzztest/usbmgrrequestright_fuzzer/project.xml b/test/fuzztest/usbmgrrequestright_fuzzer/project.xml new file mode 100644 index 0000000..6e8ad2c --- /dev/null +++ b/test/fuzztest/usbmgrrequestright_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/usbmgrrequestright_fuzzer/usbmgrrequestright_fuzzer.cpp b/test/fuzztest/usbmgrrequestright_fuzzer/usbmgrrequestright_fuzzer.cpp new file mode 100644 index 0000000..5b56750 --- /dev/null +++ b/test/fuzztest/usbmgrrequestright_fuzzer/usbmgrrequestright_fuzzer.cpp @@ -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; +} + diff --git a/test/fuzztest/usbmgrrequestright_fuzzer/usbmgrrequestright_fuzzer.h b/test/fuzztest/usbmgrrequestright_fuzzer/usbmgrrequestright_fuzzer.h new file mode 100644 index 0000000..3f188e8 --- /dev/null +++ b/test/fuzztest/usbmgrrequestright_fuzzer/usbmgrrequestright_fuzzer.h @@ -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 diff --git a/test/native/BUILD.gn b/test/native/BUILD.gn index 061a329..363e3c5 100644 --- a/test/native/BUILD.gn +++ b/test/native/BUILD.gn @@ -16,5 +16,5 @@ import("//build/test.gni") group("usb_unittest_test") { testonly = true - deps = [ "service_unittest:unittest" ] + deps = [] } diff --git a/test/native/service_unittest/BUILD.gn b/test/native/service_unittest/BUILD.gn index 5ddd66c..36a22b3 100644 --- a/test/native/service_unittest/BUILD.gn +++ b/test/native/service_unittest/BUILD.gn @@ -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", + ] }