• 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 "notifymetadatabindingevent_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 "NotifyMetaDataBindingEventFuzzTest"
28 
29 namespace OHOS {
30 namespace Msdp {
31 namespace DeviceStatus {
32 class BoomerangClientTestCallback : public OHOS::Msdp::DeviceStatus::BoomerangCallbackStub {
33 public:
34 
35 private:
36     OHOS::Msdp::DeviceStatus::BoomerangData data_;
37 };
38 
39 namespace OHOS {
40 const std::u16string FORMMGR_INTERFACE_TOKEN { u"ohos.msdp.Idevicestatus" };
41 
NotifyMetaDataBindingEventFuzzTest(const uint8_t * data,size_t size)42 bool NotifyMetaDataBindingEventFuzzTest(const uint8_t* data, size_t size)
43 {
44     MessageParcel datas;
45     sptr<IRemoteBoomerangCallback> callback = new (std::nothrow) BoomerangClientTestCallback();
46     if (!datas.WriteInterfaceToken(FORMMGR_INTERFACE_TOKEN) ||
47         !datas.WriteBuffer(data, size) || !datas.RewindRead(0) || !datas.WriteRemoteObject(callback->AsObject())) {
48         return false;
49     }
50     MessageParcel reply;
51     MessageOption option;
52     DelayedSingleton<DeviceStatusService>::GetInstance()->OnRemoteRequest(
53         static_cast<uint32_t>(Msdp::IIntentionIpcCode::COMMAND_NOTIFY_METADATA_BINDING_EVENT), datas, reply, option);
54     return true;
55 }
56 } // namespace OHOS
57 
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)58 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
59 {
60     /* Run your code on data */
61     if (data == nullptr) {
62         return 0;
63     }
64 
65     OHOS::NotifyMetaDataBindingEventFuzzTest(data, size);
66     return 0;
67 }
68 } // namespace DeviceStatus
69 } // namespace Msdp
70 } // namespace OHOS