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 "windowsessionmgrstubsessionimpllifecycle_fuzzer.h"
17
18 #include <cstddef>
19 #include <cstdint>
20 #include <parcel.h>
21 #include <securec.h>
22
23 #include <iremote_stub.h>
24 #include "message_option.h"
25 #include "message_parcel.h"
26 #include "marshalling_helper.h"
27 #include "scene_session_manager.h"
28 #include "scene_session_manager_stub.h"
29 #include "session/container/include/zidl/session_stage_ipc_interface_code.h"
30 #include "window_session_impl.h"
31
32 using namespace OHOS::Rosen;
33
34 namespace OHOS {
35 namespace {
36 constexpr size_t DATA_MIN_SIZE = 2;
37 }
38
SessionStageLifecycleIpcInterfaceCodeTest(sptr<WindowSessionImpl> & stageStub,MessageParcel & parcel)39 void SessionStageLifecycleIpcInterfaceCodeTest(sptr<WindowSessionImpl>& stageStub, MessageParcel& parcel)
40 {
41 MessageParcel reply;
42 MessageOption option;
43 parcel.RewindRead(0);
44 stageStub->OnRemoteRequest(static_cast<uint32_t>(Rosen::SessionStageInterfaceCode::TRANS_ID_GET_ROUTER_STACK_INFO),
45 parcel, reply, option);
46 }
47
DoSomethingInterestingWithMyAPI(const uint8_t * data,size_t size)48 bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size)
49 {
50 if (data == nullptr || size < DATA_MIN_SIZE) {
51 return false;
52 }
53 MessageParcel parcel;
54 parcel.WriteInterfaceToken(SessionStageStub::GetDescriptor());
55 parcel.WriteBuffer(data, size);
56 sptr<WindowOption> windowOption = sptr<WindowOption>::MakeSptr();
57 sptr<WindowSessionImpl> stageStub = sptr<WindowSessionImpl>::MakeSptr(windowOption);
58 SessionStageLifecycleIpcInterfaceCodeTest(stageStub, parcel);
59 return true;
60 }
61 } // namespace OHOS
62
63 /* Fuzzer entry point */
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)64 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
65 {
66 /* Run your code on data */
67 OHOS::DoSomethingInterestingWithMyAPI(data, size);
68 return 0;
69 }
70