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 "i_anco_consumer.h"
17 #include "ancowindows_fuzzer.h"
18 #include "fuzzer/FuzzedDataProvider.h"
19 #include "mmi_log.h"
20
21 #include "securec.h"
22
23 #undef MMI_LOG_TAG
24 #define MMI_LOG_TAG "AncoWindowsFuzzTest"
25
26 namespace OHOS {
27 namespace MMI {
AncoWindowsFuzzTest(const uint8_t * data,size_t size)28 bool AncoWindowsFuzzTest(const uint8_t *data, size_t size)
29 {
30 AncoWindows ancoWindows;
31 FuzzedDataProvider provider(data, size);
32 bool update = provider.ConsumeBool();
33 ancoWindows.updateType = update ? ANCO_WINDOW_UPDATE_TYPE::ALL : ANCO_WINDOW_UPDATE_TYPE::INCREMENT;
34
35 int32_t focusWindowId = provider.ConsumeIntegral<int32_t>();
36 ancoWindows.focusWindowId = focusWindowId;
37
38 AncoWindowInfo windowInfo;
39 int32_t id = provider.ConsumeIntegral<int32_t>();
40 windowInfo.id = id;
41 ancoWindows.windows.push_back(windowInfo);
42
43 id = provider.ConsumeIntegral<int32_t>();
44 AncoWindowInfo windowInfo2;
45 windowInfo2.id = id;
46 ancoWindows.windows.push_back(windowInfo2);
47
48 Parcel parcel;
49 ancoWindows.Marshalling(parcel);
50 ancoWindows.ReadFromParcel(parcel);
51 ancoWindows.Unmarshalling(parcel);
52 MMI_HILOGD("AncoWindowsFuzzTest");
53 return true;
54 }
55 } // MMI
56 } // OHOS
57
58 /* Fuzzer entry point */
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)59 extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
60 {
61 /* Run your code on data */
62 if (data == nullptr) {
63 return 0;
64 }
65
66 OHOS::MMI::AncoWindowsFuzzTest(data, size);
67 return 0;
68 }
69