1 /*
2 * Copyright (c) 2024 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 "updatepreviewstyle_fuzzer.h"
17
18 #include "singleton.h"
19
20 #define private public
21 #include "devicestatus_service.h"
22 #include "fi_log.h"
23 #include "message_parcel.h"
24 #include "preview_style_packer.h"
25
26 #undef LOG_TAG
27 #define LOG_TAG "UpdatePreviewStyleFuzzTest"
28
29 namespace OHOS {
30 namespace Msdp {
31 namespace DeviceStatus {
32
33 namespace OHOS {
34 constexpr uint32_t FOREGROUND_COLOR_IN { 0x33FF0000 };
35
UpdatePreviewStyleFuzzTest(const uint8_t * data,size_t size)36 bool UpdatePreviewStyleFuzzTest(const uint8_t* data, size_t size)
37 {
38 const std::u16string FORMMGR_DEVICE_TOKEN { u"ohos.msdp.Idevicestatus" };
39 MessageParcel datas;
40 if (!datas.WriteInterfaceToken(FORMMGR_DEVICE_TOKEN)) {
41 FI_HILOGE("Failed to write interface token");
42 return false;
43 }
44
45 PreviewStyle previewStyle;
46 previewStyle.types = { PreviewType::FOREGROUND_COLOR };
47 previewStyle.foregroundColor = FOREGROUND_COLOR_IN;
48 if (PreviewStylePacker::Marshalling(previewStyle, datas) != RET_OK) {
49 FI_HILOGE("Marshalling previewStyle failed");
50 return false;
51 }
52 if (!datas.WriteBuffer(data, size) || !datas.RewindRead(0)) {
53 FI_HILOGE("Failed to write buffer");
54 return false;
55 }
56 MessageOption option;
57 MessageParcel reply;
58 DelayedSingleton<DeviceStatusService>::GetInstance()->OnRemoteRequest(
59 static_cast<uint32_t>(Msdp::DeviceInterfaceCode::UPDATE_PREVIEW_STYLE), datas, reply, option);
60 return true;
61 }
62 } // namespace OHOS
63
64 /* Fuzzer entry point */
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)65 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
66 {
67 /* Run your code on data */
68 if (data == nullptr) {
69 return 0;
70 }
71
72 OHOS::UpdatePreviewStyleFuzzTest(data, size);
73 return 0;
74 }
75 } // namespace DeviceStatus
76 } // namespace Msdp
77 } // namespace OHOS
78