• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "dmsfreeinstallcallbackstub_fuzzer.h"
17 
18 #include <fuzzer/FuzzedDataProvider.h>
19 
20 #include "dms_free_install_callback.h"
21 #include "distributed_sched_interface.h"
22 #include "mock_fuzz_util.h"
23 #include "parcel_helper.h"
24 
25 namespace OHOS {
26 namespace DistributedSchedule {
27 namespace {
28 const uint32_t ONE = 1;
29 }
OnInstallFinishedInnerFuzzTest(const uint8_t * data,size_t size)30 bool OnInstallFinishedInnerFuzzTest(const uint8_t* data, size_t size)
31 {
32     if ((data == nullptr) || (size < sizeof(int32_t))) {
33         return false;
34     }
35     FuzzUtil::MockPermission();
36     int64_t taskId = 0;
37     IDistributedSched::FreeInstallInfo info;
38     std::shared_ptr<DmsFreeInstallCallback> freeInstall_ =
39         std::make_shared<DmsFreeInstallCallback>(taskId, info);
40     uint32_t code = ONE;
41     MessageParcel dataParcel;
42     MessageParcel reply;
43     MessageOption option;
44     std::u16string descriptor = DmsFreeInstallCallbackStub::GetDescriptor();
45     freeInstall_->OnRemoteRequest(code, dataParcel, reply, option);
46 
47     dataParcel.WriteInterfaceToken(descriptor);
48     freeInstall_->OnRemoteRequest(code, dataParcel, reply, option);
49 
50     code = static_cast<uint32_t>(IDRreeInstallCallbackInterfaceCode::ON_FREE_INSTALL_DONE);
51     FuzzedDataProvider fdp(data, size);
52     int32_t resultCode = fdp.ConsumeIntegral<int32_t>();
53     int32_t requestCode = fdp.ConsumeIntegral<int32_t>();
54     dataParcel.WriteInt32(resultCode);
55     dataParcel.WriteInt32(requestCode);
56     freeInstall_->OnRemoteRequest(code, dataParcel, reply, option);
57 
58     AAFwk::Want want;
59     dataParcel.WriteParcelable(&want);
60     freeInstall_->OnRemoteRequest(code, dataParcel, reply, option);
61     return true;
62 }
63 }
64 }
65 
66 /* Fuzzer entry point */
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)67 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
68 {
69     OHOS::DistributedSchedule::OnInstallFinishedInnerFuzzTest(data, size);
70     return 0;
71 }