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 "backupsainitincrementalbackupsession_fuzzer.h"
17
18 #include <cstddef>
19 #include <cstdint>
20 #include <cstring>
21 #include <climits>
22 #include <fuzzer/FuzzedDataProvider.h>
23 #include <vector>
24
25 #include "message_parcel.h"
26 #include "sandbox_helper.h"
27 #include "service.h"
28 #include "service_proxy.h"
29 #include "service_reverse.h"
30 #include "service_stub.h"
31 #include "securec.h"
32 #include "system_ability.h"
33
34 using namespace std;
35 using namespace OHOS::FileManagement::Backup;
36
37 namespace OHOS {
38 constexpr int32_t SERVICE_ID = 5203;
39
CmdInitIncrementalBackupSessionFuzzTest(const uint8_t * data,size_t size)40 bool CmdInitIncrementalBackupSessionFuzzTest(const uint8_t *data, size_t size)
41 {
42 MessageParcel datas;
43 datas.WriteInterfaceToken(ServiceStub::GetDescriptor());
44 datas.WriteBuffer(data, size);
45 datas.RewindRead(0);
46 MessageParcel reply;
47 MessageOption option;
48
49 sptr service(new Service(SERVICE_ID));
50 uint32_t code = static_cast<uint32_t>(IServiceIpcCode::COMMAND_INIT_INCREMENTAL_BACKUP_SESSION);
51 service->OnRemoteRequest(code, datas, reply, option);
52 return true;
53 }
54 } // namespace OHOS
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 try {
60 OHOS::CmdInitIncrementalBackupSessionFuzzTest(data, size);
61 } catch (OHOS::FileManagement::Backup::BError &err) {
62 HILOGE("BackupSaFuzzTest error");
63 } catch (...) {
64 HILOGE("BackupSaFuzzTest exception");
65 }
66 return 0;
67 }