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 "localpendingwant_fuzzer.h"
17
18 #include <cstddef>
19 #include <cstdint>
20 #include <fuzzer/FuzzedDataProvider.h>
21
22 #include "local_pending_want.h"
23 #include "parcel.h"
24
25 using namespace OHOS::AbilityRuntime::WantAgent;
26
27 namespace OHOS {
28 namespace {
29 constexpr size_t STRING_MAX_LENGTH = 128;
30 const std::string GET_BUNDLE_INFO_PERMISSION = "ohos.permission.GET_BUNDLE_INFO";
31 }
DoSomethingInterestingWithMyAPI(const uint8_t * data,size_t size)32 bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size)
33 {
34 std::string bundleName;
35 std::shared_ptr<AAFwk::Want> want = std::make_shared<AAFwk::Want>();
36 int32_t operType;
37 sptr<CompletedDispatcher> callBack;
38 std::shared_ptr<AAFwk::WantParams> extraInfo;
39 Parcel paramsParcel;
40 FuzzedDataProvider fdp(data, size);
41 paramsParcel.WriteString(fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH));
42 paramsParcel.WriteInt32(fdp.ConsumeIntegral<int32_t>());
43 AAFwk::WantParams* params = AAFwk::WantParams::Unmarshalling(paramsParcel);
44 if (params) {
45 extraInfo = std::make_shared<AAFwk::WantParams>(*params);
46 }
47 TriggerInfo paramsInfo(GET_BUNDLE_INFO_PERMISSION, extraInfo, want, 0);
48 sptr<IRemoteObject> callerToken;
49 bundleName = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH);
50 operType = fdp.ConsumeIntegral<int32_t>();
51 LocalPendingWant localPendingWant = LocalPendingWant(bundleName, want, operType);
52 localPendingWant.GetBundleName();
53 localPendingWant.SetBundleName(bundleName);
54 localPendingWant.GetUid();
55 localPendingWant.GetType();
56 localPendingWant.SetType(operType);
57 localPendingWant.GetWant();
58 localPendingWant.SetWant(want);
59 localPendingWant.GetHashCode();
60 localPendingWant.GetTokenId();
61 localPendingWant.Send(callBack, paramsInfo, callerToken);
62 localPendingWant.Marshalling(paramsParcel);
63 std::shared_ptr<LocalPendingWant> localWant = std::make_shared<LocalPendingWant>(bundleName, want, operType);
64 std::shared_ptr<LocalPendingWant> otherWant = std::make_shared<LocalPendingWant>(bundleName, want, operType);
65 localPendingWant.IsEquals(localWant, otherWant);
66 return true;
67 }
68 }
69
70 /* Fuzzer entry point */
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)71 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
72 {
73 /* Run your code on data */
74 OHOS::DoSomethingInterestingWithMyAPI(data, size);
75 return 0;
76 }