• 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 "boomerangsubscribe_fuzzer.h"
17 
18 #include "singleton.h"
19 
20 #define private public
21 #include "boomerang_callback_stub.h"
22 #include "devicestatus_service.h"
23 #include "fi_log.h"
24 #include "message_parcel.h"
25 
26 #undef LOG_TAG
27 #define LOG_TAG "BoomerangSubscribeFuzzTest"
28 
29 namespace OHOS {
30 namespace Msdp {
31 namespace DeviceStatus {
32 class BoomerangClientTestCallback : public BoomerangCallbackStub {
33     public:
34     private:
35     BoomerangData data_;
36 };
37 namespace OHOS {
38 const std::u16string FORMMGR_INTERFACE_TOKEN { u"ohos.msdp.Idevicestatus" };
39 
BoomerangSubscribeFuzzTest(const uint8_t * data,size_t size)40 bool BoomerangSubscribeFuzzTest(const uint8_t* data, size_t size)
41 {
42     MessageParcel datas;
43     sptr<IRemoteBoomerangCallback> callback = new (std::nothrow) BoomerangClientTestCallback();
44     if (!datas.WriteInterfaceToken(FORMMGR_INTERFACE_TOKEN) ||
45         !datas.WriteBuffer(data, size) || !datas.RewindRead(0) || !datas.WriteRemoteObject(callback->AsObject())) {
46         return false;
47     }
48     MessageParcel reply;
49     MessageOption option;
50     DelayedSingleton<DeviceStatusService>::GetInstance()->OnRemoteRequest(
51         static_cast<uint32_t>(Msdp::IIntentionIpcCode::COMMAND_SUBSCRIBE_CALLBACK), datas, reply, option);
52     return true;
53 }
54 } // namespace OHOS
55 /* Fuzzer entry point */
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)56 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
57 {
58     /* Run your code on data */
59     if (data == nullptr) {
60         return 0;
61     }
62 
63     OHOS::BoomerangSubscribeFuzzTest(data, size);
64     return 0;
65 }
66 } // namespace DeviceStatus
67 } // namespace Msdp
68 } // namespace OHOS
69