1 /*
2  * Copyright (c) 2023 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 "sys_installer_fuzzer.h"
17 
18 #include <array>
19 #include <cstddef>
20 #include <cstdint>
21 #include <iostream>
22 #include <string>
23 #include <vector>
24 #include "isys_installer.h"
25 #include "isys_installer_callback_func.h"
26 #include "sys_installer_kits_impl.h"
27 
28 namespace OHOS {
29 using namespace SysInstaller;
30 
FuzzSysInstaller(const uint8_t * data,size_t size)31 void FuzzSysInstaller(const uint8_t* data, size_t size)
32 {
33     SysInstallerKitsImpl::GetInstance().SysInstallerInit();
34     SysInstallerKitsImpl::GetInstance().SetUpdateCallback(nullptr);
35     SysInstallerKitsImpl::GetInstance().StartUpdatePackageZip(std::string(reinterpret_cast<const char*>(data), size));
36     const std::string pkgPath = "/data/updater/fuzz/updater.zip";
37     const std::string location = "location";
38     SysInstallerKitsImpl::GetInstance().GetUpdateStatus();
39     SysInstallerKitsImpl::GetInstance().StartUpdateParaZip(pkgPath,
40         location, std::string(reinterpret_cast<const char*>(data), size));
41     SysInstallerKitsImpl::GetInstance().AccDecompressAndVerifyPkg(
42         pkgPath, std::string(reinterpret_cast<const char*>(data), size), 1);
43     SysInstallerKitsImpl::GetInstance().AccDeleteDir(std::string(reinterpret_cast<const char*>(data), size));
44 }
45 }
46 
47 /* Fuzzer entry point */
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)48 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
49 {
50     /* Run your code on data */
51     OHOS::FuzzSysInstaller(data, size);
52     return 0;
53 }
54 
55