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 "bundlemanagercallbackstub_fuzzer.h"
17
18 #include <fuzzer/FuzzedDataProvider.h>
19
20 #include "bundle/bundle_manager_callback_stub.h"
21 #include "mock_fuzz_util.h"
22
23 namespace OHOS {
24 namespace DistributedSchedule {
25
OnQueryInstallationFinishedInnerFuzzTest(const uint8_t * data,size_t size)26 bool OnQueryInstallationFinishedInnerFuzzTest(const uint8_t* data, size_t size)
27 {
28 if ((data == nullptr) || (size < sizeof(int32_t))) {
29 return false;
30 }
31 FuzzUtil::MockPermission();
32 std::shared_ptr<DmsBundleManagerCallbackStub> bundleManager_ =
33 std::make_shared<DmsBundleManagerCallbackStub>();
34 uint32_t code = 0;
35 MessageParcel dataParcel;
36 MessageParcel reply;
37 MessageOption option;
38 bundleManager_->OnRemoteRequest(code, dataParcel, reply, option);
39
40 std::u16string descriptor = bundleManager_->GetDescriptor();
41 dataParcel.WriteInterfaceToken(descriptor);
42 bundleManager_->OnRemoteRequest(code, dataParcel, reply, option);
43
44 code = static_cast<uint32_t>(IDBundleManagerCallbackInterfaceCod::ON_QUERY_INSTALLATION_DONE);
45 FuzzedDataProvider fdp(data, size);
46 int32_t resultCode = fdp.ConsumeIntegral<int32_t>();
47 uint32_t versionCode = fdp.ConsumeIntegral<uint32_t>();
48 int32_t missionId = fdp.ConsumeIntegral<int32_t>();
49 dataParcel.WriteInt32(resultCode);
50 dataParcel.WriteUint32(versionCode);
51 dataParcel.WriteInt32(missionId);
52 bundleManager_->OnRemoteRequest(code, dataParcel, reply, option);
53 bundleManager_->OnQueryInstallationFinishedInner(dataParcel, reply);
54 return true;
55 }
56 }
57 }
58
59 /* Fuzzer entry point */
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)60 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
61 {
62 OHOS::DistributedSchedule::OnQueryInstallationFinishedInnerFuzzTest(data, size);
63 return 0;
64 }