1 /*
2 * Copyright (c) 2022 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include "usbqueryports_fuzzer.h"
17 #include "usb_port_impl.h"
18 #include "hdf_log.h"
19 #include "securec.h"
20 #include "usbcommonfunction_fuzzer.h"
21 #include "v1_0/iusb_interface.h"
22
23 using namespace OHOS::HDI::Usb::V1_0;
24
25 namespace OHOS {
26 namespace USB {
UsbQueryPortsFuzzTest(const uint8_t * data,size_t size)27 bool UsbQueryPortsFuzzTest(const uint8_t *data, size_t size)
28 {
29 (void)size;
30 (void)data;
31 sptr<HDI::Usb::V2_0::IUsbPortInterface> usbPortInterface_ = nullptr;
32 usbPortInterface_ = HDI::Usb::V2_0::IUsbPortInterface::Get();
33 if (usbPortInterface_ == nullptr) {
34 HDF_LOGE("%{public}s:usbPortInterface_::Get() failed.", __func__);
35 return false;
36 }
37 std::vector<HDI::Usb::V2_0::UsbPort> portList;
38 auto ret = usbPortInterface_->QueryPorts(portList);
39 if (ret != 0) {
40 return false;
41 }
42
43 return true;
44 }
45 } // namespace USB
46 } // namespace OHOS
47
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)48 extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
49 {
50 OHOS::USB::UsbQueryPortsFuzzTest(data, size);
51 return 0;
52 }