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 "setmousescrollrows_fuzzer.h"
17
18 #include "securec.h"
19
20 #include "input_manager.h"
21 #include "mmi_log.h"
22
23 #undef MMI_LOG_TAG
24 #define MMI_LOG_TAG "SetMouseScrollRowsFuzzTest"
25
26 namespace OHOS {
27 namespace MMI {
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 size_t objectSize = sizeof(object);
32 if (objectSize > size) {
33 return 0;
34 }
35 errno_t ret = memcpy_s(&object, objectSize, data, objectSize);
36 if (ret != EOK) {
37 return 0;
38 }
39 return objectSize;
40 }
41
SetMouseScrollRowsFuzzTest(const uint8_t * data,size_t size)42 void SetMouseScrollRowsFuzzTest(const uint8_t* data, size_t size)
43 {
44 size_t startPos = 0;
45 int32_t rowsBefore;
46 int32_t rowsAfter;
47 startPos += GetObject<int32_t>(rowsBefore, data + startPos, size - startPos);
48 MMI_HILOGD("SetMouseScrollRows start");
49 InputManager::GetInstance()->SetMouseScrollRows(rowsBefore);
50 InputManager::GetInstance()->GetMouseScrollRows(rowsAfter);
51 }
52
SetPointerSizeFuzzTest(const uint8_t * data,size_t size)53 void SetPointerSizeFuzzTest(const uint8_t* data, size_t size)
54 {
55 size_t startPos = 0;
56 int32_t pointerSizeBefore;
57 int32_t pointerSizeAfter;
58 startPos += GetObject<int32_t>(pointerSizeBefore, data + startPos, size - startPos);
59 InputManager::GetInstance()->SetPointerSize(pointerSizeBefore);
60 InputManager::GetInstance()->GetPointerSize(pointerSizeAfter);
61 }
62
GetAllMmiSubscribedEventsFuzzTest(const uint8_t * data,size_t size)63 void GetAllMmiSubscribedEventsFuzzTest(const uint8_t* data, size_t size)
64 {
65 size_t startPos = 0;
66 int32_t rowsBefore;
67 startPos += GetObject<int32_t>(rowsBefore, data + startPos, size - startPos);
68 std::map<std::tuple<int32_t, int32_t, std::string>, int32_t> map;
69 MMI_HILOGD("GetAllMmiSubscribedEventsFuzzTest start");
70 InputManager::GetInstance()->GetAllMmiSubscribedEvents(map);
71 }
72
SetNapStatusFuzzTest(const uint8_t * data,size_t size)73 void SetNapStatusFuzzTest(const uint8_t* data, size_t size)
74 {
75 size_t startPos = 0;
76 int32_t rowsBefore;
77 startPos += GetObject<int32_t>(rowsBefore, data + startPos, size - startPos);
78 int32_t pid = 10;
79 int32_t uid = 20;
80 std::string bundleName = "name";
81 int32_t state = 2;
82 InputManager::GetInstance()->SetNapStatus(pid, uid, bundleName, state);
83 }
84
SetHoverScrollStateFuzzTest(const uint8_t * data,size_t size)85 void SetHoverScrollStateFuzzTest(const uint8_t* data, size_t size)
86 {
87 size_t startPos = 0;
88 int32_t rowsBefore;
89 startPos += GetObject<int32_t>(rowsBefore, data + startPos, size - startPos);
90 bool isHoverState = true;
91 InputManager::GetInstance()->SetHoverScrollState(isHoverState);
92 bool notHoverState = false;
93 InputManager::GetInstance()->SetHoverScrollState(notHoverState);
94 bool getHoverState = true;
95 InputManager::GetInstance()->GetHoverScrollState(getHoverState);
96 }
97
PointerColorFuzzTest(const uint8_t * data,size_t size)98 void PointerColorFuzzTest(const uint8_t* data, size_t size)
99 {
100 size_t startPos = 0;
101 int32_t rowsBefore;
102 startPos += GetObject<int32_t>(rowsBefore, data + startPos, size - startPos);
103 int32_t firstColor = 0xA946F1;
104 InputManager::GetInstance()->SetPointerColor(firstColor);
105 int32_t getColor = 3;
106 InputManager::GetInstance()->GetPointerColor(getColor);
107 }
108
ClearWindowPointerStyleFuzzTest(const uint8_t * data,size_t size)109 void ClearWindowPointerStyleFuzzTest(const uint8_t* data, size_t size)
110 {
111 size_t startPos = 0;
112 int32_t rowsBefore;
113 startPos += GetObject<int32_t>(rowsBefore, data + startPos, size - startPos);
114 int32_t pid = 0;
115 int32_t uid = 0;
116 InputManager::GetInstance()->ClearWindowPointerStyle(pid, uid);
117 }
118
SetKeyboardRepeatDelayFuzzTest(const uint8_t * data,size_t size)119 void SetKeyboardRepeatDelayFuzzTest(const uint8_t* data, size_t size)
120 {
121 size_t startPos = 0;
122 int32_t rowsBefore;
123 startPos += GetObject<int32_t>(rowsBefore, data + startPos, size - startPos);
124 int32_t delayTime = 10;
125 InputManager::GetInstance()->SetKeyboardRepeatDelay(delayTime);
126 }
127 } // MMI
128 } // OHOS
129
130 /* Fuzzer entry point */
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)131 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
132 {
133 /* Run your code on data */
134 OHOS::MMI::SetMouseScrollRowsFuzzTest(data, size);
135 OHOS::MMI::SetPointerSizeFuzzTest(data, size);
136 OHOS::MMI::GetAllMmiSubscribedEventsFuzzTest(data, size);
137 OHOS::MMI::SetNapStatusFuzzTest(data, size);
138 OHOS::MMI::SetHoverScrollStateFuzzTest(data, size);
139 OHOS::MMI::PointerColorFuzzTest(data, size);
140 OHOS::MMI::ClearWindowPointerStyleFuzzTest(data, size);
141 OHOS::MMI::SetKeyboardRepeatDelayFuzzTest(data, size);
142 return 0;
143 }
144
145