• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 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 #define private public
16 #define protected public
17 
18 #include <cstddef>
19 #include <cstdint>
20 
21 #include "app_control_proxy.h"
22 
23 #include "defaultapprdb_fuzzer.h"
24 #include "default_app_rdb.h"
25 
26 using namespace OHOS::AppExecFwk;
27 namespace OHOS {
DoSomethingInterestingWithMyAPI(const uint8_t * data,size_t size)28     bool DoSomethingInterestingWithMyAPI(const uint8_t *data, size_t size)
29     {
30         bool ret = false;
31         std::string type = "IMAGE";
32 
33         BundleInfo bundleInfo;
34         Element element;
35         element.bundleName = "";
36         auto defaultAppDb_ = std::make_shared<DefaultAppRdb>();
37         defaultAppDb_->GetDefaultApplicationInfo(reinterpret_cast<uintptr_t>(data), type, element);
38         std::map<std::string, Element> currentInfos;
39         defaultAppDb_->GetDefaultApplicationInfos(reinterpret_cast<uintptr_t>(data), currentInfos);
40         std::map<std::string, Element> newInfos;
41         defaultAppDb_->SetDefaultApplicationInfos(reinterpret_cast<uintptr_t>(data), newInfos);
42         defaultAppDb_->SetDefaultApplicationInfo(reinterpret_cast<uintptr_t>(data), type, element);
43         defaultAppDb_->DeleteDefaultApplicationInfos(reinterpret_cast<uintptr_t>(data));
44         defaultAppDb_->DeleteDefaultApplicationInfo(reinterpret_cast<uintptr_t>(data), type);
45         defaultAppDb_->RegisterDeathListener();
46         defaultAppDb_->UnRegisterDeathListener();
47         defaultAppDb_->LoadDefaultApplicationConfig();
48         defaultAppDb_->LoadBackUpDefaultApplicationConfig();
49         defaultAppDb_->ConvertMimeTypeToUtd();
50         defaultAppDb_->DeleteDataFromDb(reinterpret_cast<uintptr_t>(data));
51         defaultAppDb_->SaveDataToDb(reinterpret_cast<uintptr_t>(data), newInfos);
52         defaultAppDb_->GetDataFromDb(reinterpret_cast<uintptr_t>(data), newInfos);
53         DefaultAppData defaultAppData;
54         const std::string DEFAULT_APP_JSON_PATH = "/etc/app/backup_default_app.json";
55         defaultAppDb_->ParseConfig(DEFAULT_APP_JSON_PATH, defaultAppData);
56         return true;
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     // Run your code on data.
63     OHOS::DoSomethingInterestingWithMyAPI(data, size);
64     return 0;
65 }