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