mirror of
https://github.com/openharmony/usb_manager.git
synced 2026-07-01 21:45:09 -04:00
fix(usb):add fuzz test case
Signed-off-by: wu-chengwen <wuchengwen4@huawei.com>
This commit is contained in:
Executable
+27
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
* 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
|
||||
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
* 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;
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
* 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_COMMON_FUZZ_H
|
||||
#define USB_COMMON_FUZZ_H
|
||||
|
||||
#include <tuple>
|
||||
|
||||
#include "usb_srv_client.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace USB {
|
||||
std::tuple<bool, const USBDevicePipe&, const UsbInterface&> UsbMgrPrepareFuzzEnv();
|
||||
} // USB
|
||||
} // OHOS
|
||||
|
||||
#endif // USB_COMMON_FUZZ_H
|
||||
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
* 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_common_fuzz.h"
|
||||
#include "usb_srv_client.h"
|
||||
#include "usb_errors.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace USB {
|
||||
std::tuple<bool, const USBDevicePipe&, const UsbInterface&> UsbMgrPrepareFuzzEnv()
|
||||
{
|
||||
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().at(1);
|
||||
ret = usbSrvClient.ClaimInterface(pipe, interface, true);
|
||||
if (ret != UEC_OK) {
|
||||
USB_HILOGE(MODULE_USB_SERVICE, "ClaimInterface failed ret=%{public}d", ret);
|
||||
usbSrvClient.Close(pipe);
|
||||
return {false, {}, {}};
|
||||
}
|
||||
|
||||
return {true, pipe, interface};
|
||||
}
|
||||
} // USB
|
||||
} // OHOS
|
||||
@@ -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,68 @@
|
||||
/*
|
||||
* 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 "usbmgrbultransfer_fuzzer.h"
|
||||
|
||||
#include "usb_srv_client.h"
|
||||
#include "usb_errors.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace USB {
|
||||
bool UsbMgrBulkTransferFuzzTest(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;
|
||||
}
|
||||
|
||||
std::vector<uint8_t> buf;
|
||||
ret = usbSrvClient.BulkTransfer(reinterpret_cast<const USBDevicePipe&>(data),
|
||||
reinterpret_cast<const USBEndpoint&>(data), buf, reinterpret_cast<int32_t>(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::UsbMgrBulkTransferFuzzTest(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 USBMGRBULTRANSFER_FUZZER_H
|
||||
#define USBMGRBULTRANSFER_FUZZER_H
|
||||
|
||||
#define FUZZ_PROJECT_NAME "usbmgrbultransfer_fuzzer"
|
||||
|
||||
#endif // USBMGRBULTRANSFER_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 "usbmgrclaiminterface_fuzzer.h"
|
||||
|
||||
#include "usb_srv_client.h"
|
||||
#include "usb_errors.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace USB {
|
||||
bool UsbMgrClaimInterfaceFuzzTest(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;
|
||||
}
|
||||
|
||||
ret = usbSrvClient.ClaimInterface(reinterpret_cast<const USBDevicePipe&>(data),
|
||||
reinterpret_cast<const UsbInterface&>(data), true);
|
||||
if (ret == UEC_OK) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
} // OHOS
|
||||
} // USB
|
||||
|
||||
/* Fuzzer entry point */
|
||||
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
|
||||
{
|
||||
/* Run your code on data */
|
||||
OHOS::USB::UsbMgrClaimInterfaceFuzzTest(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 USBMGRCLAIMINTERFACE_FUZZER_H
|
||||
#define USBMGRCLAIMINTERFACE_FUZZER_H
|
||||
|
||||
#define FUZZ_PROJECT_NAME "usbmgrclaiminterface_fuzzer"
|
||||
|
||||
#endif // USBMGRCLAIMINTERFACE_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 "usbmgrclose_fuzzer.h"
|
||||
|
||||
#include "usb_srv_client.h"
|
||||
#include "usb_errors.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace USB {
|
||||
bool UsbMgrCloseFuzzTest(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.Close(reinterpret_cast<const USBDevicePipe&>(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::UsbMgrCloseFuzzTest(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 USBMGRCLOSE_FUZZER_H
|
||||
#define USBMGRCLOSE_FUZZER_H
|
||||
|
||||
#define FUZZ_PROJECT_NAME "usbmgrclose_fuzzer"
|
||||
|
||||
#endif // USBMGRCLOSE_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,67 @@
|
||||
/*
|
||||
* 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 "usbmgrcontroltransfer_fuzzer.h"
|
||||
|
||||
#include "usb_srv_client.h"
|
||||
#include "usb_errors.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace USB {
|
||||
bool UsbMgrControlTransferFuzzTest(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;
|
||||
}
|
||||
|
||||
std::vector<uint8_t> buf;
|
||||
ret = usbSrvClient.ControlTransfer(reinterpret_cast<const USBDevicePipe&>(data),
|
||||
reinterpret_cast<const UsbCtrlTransfer&>(data), buf);
|
||||
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::UsbMgrControlTransferFuzzTest(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 USBMGRCONTROLTRANSFER_FUZZER_H
|
||||
#define USBMGRCONTROLTRANSFER_FUZZER_H
|
||||
|
||||
#define FUZZ_PROJECT_NAME "usbmgrcontroltransfer_fuzzer"
|
||||
|
||||
#endif // USBMGRCONTROLTRANSFER_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,54 @@
|
||||
/*
|
||||
* 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 "usbmgrhasright_fuzzer.h"
|
||||
|
||||
#include "usb_srv_client.h"
|
||||
#include "usb_errors.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace USB {
|
||||
bool UsbMgrHasRightFuzzTest(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(std::string((const char*)data))) {
|
||||
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::UsbMgrHasRightFuzzTest(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 USBMGRHASRIGHT_FUZZER_H
|
||||
#define USBMGRHASRIGHT_FUZZER_H
|
||||
|
||||
#define FUZZ_PROJECT_NAME "usbmgrhasright_fuzzer"
|
||||
|
||||
#endif // USBMGRHASRIGHT_FUZZER_H
|
||||
@@ -0,0 +1,14 @@
|
||||
# Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
FUZZ
|
||||
@@ -0,0 +1,25 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
-->
|
||||
<fuzz_config>
|
||||
<fuzztest>
|
||||
<!-- maximum length of a test input -->
|
||||
<max_len>1000</max_len>
|
||||
<!-- maximum total time in seconds to run the fuzzer -->
|
||||
<max_total_time>300</max_total_time>
|
||||
<!-- memory usage limit in Mb -->
|
||||
<rss_limit_mb>4096</rss_limit_mb>
|
||||
</fuzztest>
|
||||
</fuzz_config>
|
||||
@@ -0,0 +1,65 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "usbmgrpiperequestwait_fuzzer.h"
|
||||
|
||||
#include "usb_srv_client.h"
|
||||
#include "usb_errors.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace USB {
|
||||
bool UsbMgrPipeRequestWaitFuzzTest(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.PipeRequestWait(reinterpret_cast<const USBDevicePipe&>(data),
|
||||
reinterpret_cast<int64_t>(data), reinterpret_cast<UsbRequest&>(data))) {
|
||||
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::UsbMgrPipeRequestWaitFuzzTest(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 USBMGRPIPEREQUESTWAIT_FUZZER_H
|
||||
#define USBMGRPIPEREQUESTWAIT_FUZZER_H
|
||||
|
||||
#define FUZZ_PROJECT_NAME "usbmgrpiperequestwait_fuzzer"
|
||||
|
||||
#endif // USBMGRPIPEREQUESTWAIT_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 "usbmgrunregbulkcallback_fuzzer.h"
|
||||
|
||||
#include "iremote_object.h"
|
||||
#include "usb_srv_client.h"
|
||||
#include "usb_errors.h"
|
||||
#include "usb_callback_test.h"
|
||||
#include "usb_common_fuzz.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace USB {
|
||||
bool UsbMgrUnRegBulkCallbackFuzzTest(const uint8_t* data, size_t /* size */)
|
||||
{
|
||||
auto[res, pipe, interface] = UsbMgrPrepareFuzzEnv();
|
||||
if (!res) {
|
||||
USB_HILOGE(MODULE_USB_SERVICE, "prepare error");
|
||||
return false;
|
||||
}
|
||||
|
||||
auto& usbSrvClient = UsbSrvClient::GetInstance();
|
||||
sptr<UsbCallbackTest> cb = new UsbCallbackTest();
|
||||
auto ret = usbSrvClient.RegBulkCallback(pipe, interface.GetEndpoints().at(1), cb);
|
||||
if (ret != UEC_OK) {
|
||||
USB_HILOGE(MODULE_USB_SERVICE, "RegBulkCallback failed ret=%{public}d", ret);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (usbSrvClient.UnRegBulkCallback(reinterpret_cast<const USBDevicePipe&>(data),
|
||||
reinterpret_cast<const USBEndpoint&>(data)) == UEC_OK) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
} // USB
|
||||
} // OHOS
|
||||
|
||||
/* Fuzzer entry point */
|
||||
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
|
||||
{
|
||||
/* Run your code on data */
|
||||
OHOS::USB::UsbMgrUnRegBulkCallbackFuzzTest(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 USBMGRUNREGBULKCALLBACK_FUZZER_H
|
||||
#define USBMGRUNREGBULKCALLBACK_FUZZER_H
|
||||
|
||||
#define FUZZ_PROJECT_NAME "usbmgrunregbulkcallback_fuzzer"
|
||||
|
||||
#endif // USBMGRUNREGBULKCALLBACK_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>
|
||||
+41
@@ -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 "usbmgrusbfunctionsfromstring_fuzzer.h"
|
||||
|
||||
#include "usb_srv_client.h"
|
||||
#include "usb_errors.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace USB {
|
||||
bool UsbMgrUsbFunctionsFromStringFuzzTest(const uint8_t* data, size_t /* size */)
|
||||
{
|
||||
auto &usbSrvClient = UsbSrvClient::GetInstance();
|
||||
if (usbSrvClient.UsbFunctionsFromString(std::string_view((const char*)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::UsbMgrUsbFunctionsFromStringFuzzTest(data, size);
|
||||
return 0;
|
||||
}
|
||||
|
||||
+21
@@ -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 USBMGRUSBFUNCTIONSFROMSTRING_FUZZER_H
|
||||
#define USBMGRUSBFUNCTIONSFROMSTRING_FUZZER_H
|
||||
|
||||
#define FUZZ_PROJECT_NAME "usbmgrusbfunctionsfromstring_fuzzer"
|
||||
|
||||
#endif // USBMGRUSBFUNCTIONSFROMSTRING_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 "usbmgrusbfunctionstostring_fuzzer.h"
|
||||
|
||||
#include "usb_srv_client.h"
|
||||
#include "usb_errors.h"
|
||||
|
||||
namespace {
|
||||
const int32_t MAX_FUNC_NUM = 6;
|
||||
}
|
||||
|
||||
namespace OHOS {
|
||||
namespace USB {
|
||||
bool UsbMgrUsbFunctionsToStringFuzzTest(const uint8_t* data, size_t /* size */)
|
||||
{
|
||||
auto &usbSrvClient = UsbSrvClient::GetInstance();
|
||||
int32_t func = reinterpret_cast<int32_t>(data);
|
||||
if (func <= MAX_FUNC_NUM) {
|
||||
func += MAX_FUNC_NUM;
|
||||
}
|
||||
|
||||
if (usbSrvClient.UsbFunctionsToString(func) != "") {
|
||||
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::UsbMgrUsbFunctionsToStringFuzzTest(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 USBMGRUSBFUNCTIONSTOSTRING_FUZZER_H
|
||||
#define USBMGRUSBFUNCTIONSTOSTRING_FUZZER_H
|
||||
|
||||
#define FUZZ_PROJECT_NAME "usbmgrusbfunctionstostring_fuzzer"
|
||||
|
||||
#endif // USBMGRUSBFUNCTIONSTOSTRING_FUZZER_H
|
||||
Reference in New Issue
Block a user