1 /*
2 * Copyright (c) 2024 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 <cstddef>
17 #include <cstdint>
18 #include <parcel.h>
19 #include <securec.h>
20
21 #include <iremote_stub.h>
22 #include "message_option.h"
23 #include "message_parcel.h"
24 #include "marshalling_helper.h"
25 #include "window.h"
26 #include "window_agent.h"
27 #include "window_impl.h"
28 #include "window_manager.h"
29 #include "windowstubget_fuzzer.h"
30
31 using namespace OHOS::Rosen;
32
33 namespace OHOS {
34 namespace {
35 constexpr size_t DATA_MIN_SIZE = 2;
36 }
37
DoSomethingInterestingWithMyAPI(const uint8_t * data,size_t size)38 bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size)
39 {
40 if (data == nullptr || size < DATA_MIN_SIZE) {
41 return false;
42 }
43
44 MessageParcel parcel;
45 MessageParcel reply;
46 MessageOption option;
47
48 parcel.WriteInterfaceToken(WindowStub::GetDescriptor());
49 parcel.WriteBuffer(data, size);
50
51 sptr<WindowOption> windowOption = new(std::nothrow)WindowOption();
52 if (windowOption == nullptr) {
53 return false;
54 }
55 sptr<WindowImpl> window = new(std::nothrow)WindowImpl(windowOption);
56 if (window == nullptr) {
57 return false;
58 }
59 sptr<WindowAgent> windowStub = new(std::nothrow)WindowAgent(window);
60 if (windowStub == nullptr) {
61 return false;
62 }
63 parcel.RewindRead(0);
64 windowStub->OnRemoteRequest(static_cast<uint32_t>(IWindow::WindowMessage::TRANS_ID_GET_WINDOW_PROPERTY),
65 parcel, reply, option);
66 parcel.RewindRead(0);
67 windowStub->OnRemoteRequest(static_cast<uint32_t>(IWindow::WindowMessage::TRANS_ID_DUMP_INFO),
68 parcel, reply, option);
69 parcel.RewindRead(0);
70 windowStub->OnRemoteRequest(static_cast<uint32_t>(IWindow::WindowMessage::TRANS_ID_RESTORE_SPLIT_WINDOW_MODE),
71 parcel, reply, option);
72 parcel.RewindRead(0);
73 windowStub->OnRemoteRequest(static_cast<uint32_t>(IWindow::WindowMessage::TRANS_ID_CONSUME_KEY_EVENT),
74 parcel, reply, option);
75 return true;
76 }
77 } // namespace.OHOS
78
79 /* Fuzzer entry point */
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)80 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
81 {
82 /* Run your code on data */
83 OHOS::DoSomethingInterestingWithMyAPI(data, size);
84 return 0;
85 }