• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 <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 "session/host/include/zidl/session_ipc_interface_code.h"
26 #include "session/host/include/zidl/session_stub.h"
27 #include "session/host/include/session.h"
28 #include "sessionstubpc_fuzzer.h"
29 
30 using namespace OHOS::Rosen;
31 
32 namespace OHOS {
33 namespace {
34 constexpr size_t DATA_MIN_SIZE = 2;
35 }
36 
SessionStubPcTest(sptr<Session> sessionStub,MessageParcel & parcel)37 void SessionStubPcTest(sptr<Session> sessionStub, MessageParcel& parcel)
38 {
39     MessageParcel reply;
40     MessageOption option;
41     parcel.RewindRead(0);
42     sessionStub->OnRemoteRequest(static_cast<uint32_t>
43         (Rosen::SessionInterfaceCode::TRANS_ID_LAYOUT_FULL_SCREEN_CHANGE),
44         parcel, reply, option);
45     parcel.RewindRead(0);
46     sessionStub->OnRemoteRequest(static_cast<uint32_t>
47         (Rosen::SessionInterfaceCode::TRANS_ID_DEFAULT_DENSITY_ENABLED),
48         parcel, reply, option);
49     parcel.RewindRead(0);
50     sessionStub->OnRemoteRequest(static_cast<uint32_t>
51         (Rosen::SessionInterfaceCode::TRANS_ID_GET_FORCE_LANDSCAPE_CONFIG),
52         parcel, reply, option);
53     parcel.RewindRead(0);
54     sessionStub->OnRemoteRequest(static_cast<uint32_t>
55         (Rosen::SessionInterfaceCode::TRANS_ID_IS_START_MOVING),
56         parcel, reply, option);
57     parcel.RewindRead(0);
58     sessionStub->OnRemoteRequest(static_cast<uint32_t>
59         (Rosen::SessionInterfaceCode::TRANS_ID_CONTAINER_MODAL_EVENT),
60         parcel, reply, option);
61     parcel.RewindRead(0);
62     sessionStub->OnRemoteRequest(static_cast<uint32_t>
63         (Rosen::SessionInterfaceCode::TRANS_ID_KEY_FRAME_ANIMATE_END),
64         parcel, reply, option);
65     parcel.RewindRead(0);
66     sessionStub->OnRemoteRequest(static_cast<uint32_t>
67         (Rosen::SessionInterfaceCode::TRANS_ID_UPDATE_KEY_FRAME_CLONE_NODE),
68         parcel, reply, option);
69     parcel.RewindRead(0);
70     sessionStub->OnRemoteRequest(static_cast<uint32_t>
71         (Rosen::SessionInterfaceCode::TRANS_ID_USE_IMPLICT_ANIMATION),
72         parcel, reply, option);
73     parcel.RewindRead(0);
74     sessionStub->OnRemoteRequest(static_cast<uint32_t>
75         (Rosen::SessionInterfaceCode::TRANS_ID_SET_SUBWINDOW_SOURCE),
76         parcel, reply, option);
77 }
78 
DoSomethingInterestingWithMyAPI(const uint8_t * data,size_t size)79 bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size)
80 {
81     if (data == nullptr || size < DATA_MIN_SIZE) {
82         return false;
83     }
84 
85     MessageParcel parcel;
86 
87     parcel.WriteInterfaceToken(SessionStub::GetDescriptor());
88     parcel.WriteBuffer(data, size);
89 
90     SessionInfo info;
91     info.abilityName_ = "stubPcFuzzTest";
92     info.bundleName_ = "stubPcFuzzTest";
93     sptr<Session> sessionStub = new (std::nothrow) Session(info);
94     if (sessionStub == nullptr) {
95         return false;
96     }
97 
98     SessionStubPcTest(sessionStub, parcel);
99 
100     return true;
101 }
102 } // namespace.OHOS
103 
104 /* Fuzzer entry point */
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)105 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
106 {
107     /* Run your code on data */
108     OHOS::DoSomethingInterestingWithMyAPI(data, size);
109     return 0;
110 }