1 /*
2 * Copyright (c) 2025 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 "touchpaddoubletapanddragstate_fuzzer.h"
17
18 #include "securec.h"
19 #include "input_manager.h"
20 #include "mmi_log.h"
21
22 #undef MMI_LOG_TAG
23 #define MMI_LOG_TAG "TouchPadDoubleTapAndDragStateFuzzTest"
24
25 namespace OHOS {
26 namespace MMI {
27
28 template <class T>
GetObject(T & object,const uint8_t * data,size_t size)29 size_t GetObject(T &object, const uint8_t *data, size_t size)
30 {
31 if (data == nullptr || size < sizeof(T)) {
32 return 0;
33 }
34 errno_t ret = memcpy_s(&object, sizeof(T), data, sizeof(T));
35 if (ret != EOK) {
36 return 0;
37 }
38 return sizeof(T);
39 }
40
TouchpadDoubleTapAndDragStateFuzzTest(const uint8_t * data,size_t size)41 void TouchpadDoubleTapAndDragStateFuzzTest(const uint8_t *data, size_t size)
42 {
43 if (data == nullptr || size < sizeof(bool)) {
44 return;
45 }
46
47 bool switchFlag = false;
48 size_t offset = GetObject<bool>(switchFlag, data, size);
49 if (offset == 0) {
50 return;
51 }
52
53 int32_t ret = InputManager::GetInstance()->SetTouchpadDoubleTapAndDragState(switchFlag);
54 MMI_HILOGD("SetTouchpadDoubleTapAndDragState return:%{public}d", ret);
55
56 bool outFlag = false;
57 ret = InputManager::GetInstance()->GetTouchpadDoubleTapAndDragState(outFlag);
58 MMI_HILOGD("GetTouchpadDoubleTapAndDragState return:%{public}d, outFlag:%{public}d", ret, outFlag);
59 }
60
61 } // namespace MMI
62 } // namespace OHOS
63
64 /* Fuzzer entry point */
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)65 extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
66 {
67 OHOS::MMI::TouchpadDoubleTapAndDragStateFuzzTest(data, size);
68 return 0;
69 }