• 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 "sessionstubnorthbound_fuzzer.h"
29 
30 using namespace OHOS::Rosen;
31 
32 namespace OHOS {
33 namespace {
34 constexpr size_t DATA_MIN_SIZE = 2;
35 }
36 
SessionStubNorthBoundTest(sptr<Session> sessionStub,MessageParcel & parcel)37 void SessionStubNorthBoundTest(sptr<Session> sessionStub, MessageParcel& parcel)
38 {
39     MessageParcel reply;
40     MessageOption option;
41 
42     parcel.RewindRead(0);
43     sessionStub->OnRemoteRequest(static_cast<uint32_t>
44         (Rosen::SessionInterfaceCode::TRANS_ID_APP_REMOVE_STARTING_WINDOW), parcel, reply, option);
45     parcel.RewindRead(0);
46     sessionStub->OnRemoteRequest(static_cast<uint32_t>
47         (Rosen::SessionInterfaceCode::TRANS_ID_TITLE_AND_DOCK_HOVER_SHOW_CHANGE), parcel, reply, option);
48     parcel.RewindRead(0);
49     sessionStub->OnRemoteRequest(static_cast<uint32_t>
50         (Rosen::SessionInterfaceCode::TRANS_ID_RESTORE_MAIN_WINDOW), parcel, reply, option);
51     parcel.RewindRead(0);
52     sessionStub->OnRemoteRequest(static_cast<uint32_t>
53         (Rosen::SessionInterfaceCode::TRANS_ID_SUB_MODAL_TYPE_CHANGE), parcel, reply, option);
54     parcel.RewindRead(0);
55     sessionStub->OnRemoteRequest(static_cast<uint32_t>
56         (Rosen::SessionInterfaceCode::TRANS_ID_MAIN_MODAL_TYPE_CHANGE), parcel, reply, option);
57     parcel.RewindRead(0);
58     sessionStub->OnRemoteRequest(static_cast<uint32_t>
59         (Rosen::SessionInterfaceCode::TRANS_ID_SET_SUPPORT_WINDOW_MODES), parcel, reply, option);
60     parcel.RewindRead(0);
61     sessionStub->OnRemoteRequest(static_cast<uint32_t>
62         (Rosen::SessionInterfaceCode::TRANS_ID_SET_WINDOW_CORNER_RADIUS), parcel, reply, option);
63     parcel.RewindRead(0);
64     sessionStub->OnRemoteRequest(static_cast<uint32_t>
65         (Rosen::SessionInterfaceCode::TRANS_ID_START_MOVING_WITH_COORDINATE), parcel, reply, option);
66     parcel.RewindRead(0);
67     sessionStub->OnRemoteRequest(static_cast<uint32_t>
68         (Rosen::SessionInterfaceCode::TRANS_ID_UPDATE_FLAG), parcel, reply, option);
69 }
70 
DoSomethingInterestingWithMyAPI(const uint8_t * data,size_t size)71 bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size)
72 {
73     if (data == nullptr || size < DATA_MIN_SIZE) {
74         return false;
75     }
76 
77     MessageParcel parcel;
78 
79     parcel.WriteInterfaceToken(SessionStub::GetDescriptor());
80     parcel.WriteBuffer(data, size);
81 
82     SessionInfo info;
83     info.abilityName_ = "stubNorthBoundFuzzTest";
84     info.bundleName_ = "stubNorthBoundFuzzTest";
85     sptr<Session> sessionStub = new (std::nothrow) Session(info);
86     if (sessionStub == nullptr) {
87         return false;
88     }
89 
90     SessionStubNorthBoundTest(sessionStub, parcel);
91 
92     return true;
93 }
94 } // namespace.OHOS
95 
96 /* Fuzzer entry point */
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)97 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
98 {
99     /* Run your code on data */
100     OHOS::DoSomethingInterestingWithMyAPI(data, size);
101     return 0;
102 }