1 /*
2 * Copyright (c) 2024-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 "abilitymgruiextensionsessioninfo_fuzzer.h"
17
18 #include <cstddef>
19 #include <cstdint>
20 #include <iostream>
21 #include <fuzzer/FuzzedDataProvider.h>
22
23 #include "securec.h"
24 #define private public
25 #include "ui_extension/ui_extension_session_info.h"
26 #undef private
27
28 using namespace OHOS::AAFwk;
29 using namespace OHOS::AbilityRuntime;
30
31 namespace OHOS {
DoSomethingInterestingWithMyAPI(const uint8_t * data,size_t size)32 bool DoSomethingInterestingWithMyAPI(const uint8_t *data, size_t size)
33 {
34 std::shared_ptr<UIExtensionSessionInfo> uiExtensionSessionInfo = std::make_shared<UIExtensionSessionInfo>();
35 Parcel parcel;
36 FuzzedDataProvider fdp(data, size);
37 parcel.WriteInt32(fdp.ConsumeIntegral<int32_t>());
38 parcel.WriteInt32(uiExtensionSessionInfo->persistentId);
39 uiExtensionSessionInfo->Marshalling(parcel);
40 parcel.WriteUint32(fdp.ConsumeIntegral<uint32_t>());
41 parcel.WriteUint32(uiExtensionSessionInfo->hostWindowId);
42 uiExtensionSessionInfo->Marshalling(parcel);
43 parcel.WriteUint32(static_cast<uint32_t>(uiExtensionSessionInfo->uiExtensionUsage));
44 uiExtensionSessionInfo->Marshalling(parcel);
45 parcel.WriteInt32(static_cast<int32_t>(uiExtensionSessionInfo->extensionAbilityType));
46 uiExtensionSessionInfo->Marshalling(parcel);
47 uiExtensionSessionInfo->Unmarshalling(parcel);
48 return true;
49 }
50 }
51
52 /* Fuzzer entry point */
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)53 extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
54 {
55 /* Run your code on data */
56 OHOS::DoSomethingInterestingWithMyAPI(data, size);
57 return 0;
58 }