1 /*
2 * Copyright (c) 2023 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 "vibratorstopv1_2_fuzzer.h"
17 #include "hdf_base.h"
18 #include "v1_2/vibrator_interface_proxy.h"
19 #include <hdf_log.h>
20 #include <securec.h>
21
22 using namespace OHOS::HDI::Vibrator;
23 using namespace OHOS::HDI::Vibrator::V1_2;
24
25 namespace OHOS {
VibratorStopV1_2FuzzTest(const uint8_t * data,size_t size)26 bool VibratorStopV1_2FuzzTest(const uint8_t* data, size_t size)
27 {
28 if (data == nullptr) {
29 return false;
30 }
31 sptr<V1_2::IVibratorInterface> g_vibratorInterface = V1_2::IVibratorInterface::Get();
32 int ret = g_vibratorInterface->StartOnce(*(uint32_t *)data);
33 if (ret != HDF_SUCCESS) {
34 HDF_LOGE("%{public}s: Vibrator Start failed, ret is [%{public}x]\n", __func__, ret);
35 return false;
36 }
37 ret = g_vibratorInterface->StopV1_2(static_cast<HdfVibratorModeV1_2>(*data));
38 if (ret != HDF_SUCCESS) {
39 HDF_LOGE("%{public}s: Vibrator Start failed, ret is [%{public}x]\n", __func__, ret);
40 return false;
41 }
42 return true;
43 }
44 }
45
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)46 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
47 {
48 if (data == nullptr) {
49 return 0;
50 }
51
52 if (size < sizeof(int32_t)) {
53 return 0;
54 }
55 OHOS::VibratorStopV1_2FuzzTest(data, size);
56 return 0;
57 }
58
59