mirror of
https://github.com/openharmony/ability_ability_runtime.git
synced 2026-08-24 12:43:16 -04:00
@@ -0,0 +1,119 @@
|
||||
# Copyright (c) 2024 Huawei Device Co., Ltd.
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
#####################hydra-fuzz###################
|
||||
import("//build/config/features.gni")
|
||||
import("//build/ohos.gni")
|
||||
import("//build/test.gni")
|
||||
import("//foundation/ability/ability_runtime/ability_runtime.gni")
|
||||
import("//foundation/ability/ability_runtime/cj_environment/cj_environment.gni")
|
||||
module_output_path = "ability_runtime/abilitymgr"
|
||||
|
||||
##############################fuzztest##########################################
|
||||
ohos_fuzztest("AbilityFrameworksCjEnvironmentFuzzTest") {
|
||||
module_out_path = module_output_path
|
||||
|
||||
fuzz_config_file = "${ability_runtime_test_path}/fuzztest/abilityframeworkscjenvironment_fuzzer"
|
||||
include_dirs = [
|
||||
"${ability_runtime_innerkits_path}/ability_manager/include",
|
||||
"${ability_runtime_innerkits_path}/dataobs_manager/include",
|
||||
"${ability_runtime_path}/cj_environment/interfaces/inner_api",
|
||||
"${ability_runtime_path}/cj_environment/frameworks/cj_environment/include",
|
||||
"${ability_runtime_native_path}/runtime",
|
||||
"${ability_runtime_native_path}/runtime/utils/include",
|
||||
"${ability_base_kits_path}/extractortool/include",
|
||||
"${ability_runtime_path}/interfaces/kits/native/appkit/ability_bundle_manager_helper",
|
||||
"${ability_runtime_innerkits_path}/app_manager/include/appmgr",
|
||||
"${ability_runtime_services_path}/abilitymgr/include",
|
||||
"${distributedschedule_path}/samgr/interfaces/innerkits/samgr_proxy/include",
|
||||
"${distributedschedule_path}/samgr/adapter/interfaces/innerkits/include/",
|
||||
"${multimodalinput_path}/interfaces/native/innerkits/event/include",
|
||||
"//third_party/zlib/contrib/minizip",
|
||||
"//third_party/zlib",
|
||||
"//third_party/jsoncpp:jsoncpp",
|
||||
]
|
||||
cflags = [
|
||||
"-g",
|
||||
"-O0",
|
||||
"-Wno-unused-variable",
|
||||
"-fno-omit-frame-pointer",
|
||||
]
|
||||
|
||||
sources = [
|
||||
"${ability_runtime_path}/cj_environment/frameworks/cj_environment/src/cj_environment.cpp",
|
||||
"abilityframeworkscjenvironment_fuzzer.cpp",
|
||||
]
|
||||
|
||||
configs = [
|
||||
"${ability_runtime_innerkits_path}/ability_manager:ability_manager_public_config",
|
||||
"${ability_runtime_services_path}/abilitymgr:abilityms_config",
|
||||
]
|
||||
|
||||
deps = [
|
||||
"${ability_runtime_innerkits_path}/ability_manager:ability_manager",
|
||||
"${ability_runtime_innerkits_path}/ability_manager:ability_start_options",
|
||||
"${ability_runtime_innerkits_path}/ability_manager:mission_info",
|
||||
"${ability_runtime_innerkits_path}/app_manager:app_manager",
|
||||
"${ability_runtime_innerkits_path}/uri_permission:uri_permission_mgr",
|
||||
"${ability_runtime_native_path}/ability/native:abilitykit_native",
|
||||
"${ability_runtime_native_path}/appkit:appkit_manager_helper",
|
||||
"${ability_runtime_path}/utils/server/startup:startup_util",
|
||||
"${ability_runtime_services_path}/abilitymgr:abilityms",
|
||||
"${ability_runtime_services_path}/common:perm_verification",
|
||||
"//third_party/jsoncpp:jsoncpp",
|
||||
"//third_party/libjpeg-turbo:turbojpeg_static",
|
||||
]
|
||||
defines = [ "WITH_EVENT_HANDLER" ]
|
||||
external_deps = [
|
||||
"ability_base:extractortool",
|
||||
"ability_base:want",
|
||||
"ability_base:zuri",
|
||||
"ability_runtime:ability_deps_wrapper",
|
||||
"ability_runtime:js_environment",
|
||||
"ability_runtime:runtime",
|
||||
"bundle_framework:appexecfwk_core",
|
||||
"c_utils:utils",
|
||||
"common_event_service:cesfwk_innerkits",
|
||||
"dsoftbus:softbus_client",
|
||||
"ets_runtime:libark_jsruntime",
|
||||
"eventhandler:libeventhandler",
|
||||
"ffrt:libffrt",
|
||||
"hilog:libhilog",
|
||||
"hitrace:hitrace_meter",
|
||||
"ipc:ipc_core",
|
||||
"napi:ace_napi",
|
||||
]
|
||||
|
||||
if (background_task_mgr_continuous_task_enable) {
|
||||
external_deps += [ "background_task_mgr:bgtaskmgr_innerkits" ]
|
||||
}
|
||||
|
||||
if (ability_runtime_graphics) {
|
||||
deps += []
|
||||
external_deps += [
|
||||
"i18n:intl_util",
|
||||
"window_manager:libwm",
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
###############################################################################
|
||||
group("fuzztest") {
|
||||
testonly = true
|
||||
deps = []
|
||||
deps += [
|
||||
# deps file
|
||||
":AbilityFrameworksCjEnvironmentFuzzTest",
|
||||
]
|
||||
}
|
||||
###############################################################################
|
||||
+106
@@ -0,0 +1,106 @@
|
||||
/*
|
||||
* Copyright (c) 2024 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "abilityframeworkscjenvironment_fuzzer.h"
|
||||
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
|
||||
#define private public
|
||||
#include "cj_environment.h"
|
||||
#undef private
|
||||
|
||||
#include "ability_record.h"
|
||||
#include "securec.h"
|
||||
|
||||
using namespace OHOS::AAFwk;
|
||||
using namespace OHOS::AppExecFwk;
|
||||
|
||||
namespace OHOS {
|
||||
namespace {
|
||||
constexpr int INPUT_ZERO = 0;
|
||||
constexpr int INPUT_ONE = 1;
|
||||
constexpr int INPUT_TWO = 2;
|
||||
constexpr int INPUT_THREE = 3;
|
||||
constexpr size_t FOO_MAX_LEN = 1024;
|
||||
constexpr size_t U32_AT_SIZE = 4;
|
||||
constexpr size_t OFFSET_ZERO = 24;
|
||||
constexpr size_t OFFSET_ONE = 16;
|
||||
constexpr size_t OFFSET_TWO = 8;
|
||||
constexpr uint8_t ENABLE = 2;
|
||||
}
|
||||
|
||||
uint32_t GetU32Data(const char* ptr)
|
||||
{
|
||||
// convert fuzz input data to an integer
|
||||
return (ptr[INPUT_ZERO] << OFFSET_ZERO) | (ptr[INPUT_ONE] << OFFSET_ONE) | (ptr[INPUT_TWO] << OFFSET_TWO) |
|
||||
ptr[INPUT_THREE];
|
||||
}
|
||||
|
||||
sptr<Token> GetFuzzAbilityToken()
|
||||
{
|
||||
sptr<Token> token = nullptr;
|
||||
AbilityRequest abilityRequest;
|
||||
abilityRequest.appInfo.bundleName = "com.example.fuzzTest";
|
||||
abilityRequest.abilityInfo.name = "MainAbility";
|
||||
abilityRequest.abilityInfo.type = AbilityType::DATA;
|
||||
std::shared_ptr<AbilityRecord> abilityRecord = AbilityRecord::CreateAbilityRecord(abilityRequest);
|
||||
if (abilityRecord) {
|
||||
token = abilityRecord->GetToken();
|
||||
}
|
||||
return token;
|
||||
}
|
||||
|
||||
bool DoSomethingInterestingWithMyAPI(const char* data, size_t size)
|
||||
{
|
||||
std::string jsonStr(data, size);
|
||||
IsCJAbility(jsonStr);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/* Fuzzer entry point */
|
||||
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
|
||||
{
|
||||
/* Run your code on data */
|
||||
if (data == nullptr) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Validate the length of size */
|
||||
if (size < OHOS::U32_AT_SIZE || size > OHOS::FOO_MAX_LEN) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
char* ch = (char*)malloc(size + 1);
|
||||
if (ch == nullptr) {
|
||||
std::cout << "malloc failed." << std::endl;
|
||||
return 0;
|
||||
}
|
||||
|
||||
(void)memset_s(ch, size + 1, 0x00, size + 1);
|
||||
if (memcpy_s(ch, size + 1, data, size) != EOK) {
|
||||
std::cout << "copy failed." << std::endl;
|
||||
free(ch);
|
||||
ch = nullptr;
|
||||
return 0;
|
||||
}
|
||||
|
||||
OHOS::DoSomethingInterestingWithMyAPI(ch, size);
|
||||
free(ch);
|
||||
ch = nullptr;
|
||||
return 0;
|
||||
}
|
||||
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
/*
|
||||
* Copyright (c) 2024 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef FUZZTEST_OHOS_ABILITY_RUNTIME_ABILITYFRAMEWORKSCJENVIRONMENT_FUZZER_H
|
||||
#define FUZZTEST_OHOS_ABILITY_RUNTIME_ABILITYFRAMEWORKSCJENVIRONMENT_FUZZER_H
|
||||
|
||||
#define FUZZ_PROJECT_NAME "abilityframeworkscjenvironment_fuzzer"
|
||||
|
||||
#endif // FUZZTEST_OHOS_ABILITY_RUNTIME_ABILITYFRAMEWORKSCJENVIRONMENT_FUZZER_H
|
||||
@@ -0,0 +1,16 @@
|
||||
/*
|
||||
* Copyright (c) 2024 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
FUZZ
|
||||
@@ -0,0 +1,25 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Copyright (c) 2024 Huawei Device Co., Ltd.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
-->
|
||||
<fuzz_config>
|
||||
<fuzztest>
|
||||
<!-- maximum length of a test input -->
|
||||
<max_len>1000</max_len>
|
||||
<!-- maximum total time in seconds to run the fuzzer -->
|
||||
<max_total_time>300</max_total_time>
|
||||
<!-- memory usage limit in Mb -->
|
||||
<rss_limit_mb>4096</rss_limit_mb>
|
||||
</fuzztest>
|
||||
</fuzz_config>
|
||||
@@ -0,0 +1,82 @@
|
||||
# Copyright (c) 2024 Huawei Device Co., Ltd.
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
#####################hydra-fuzz###################
|
||||
import("//build/config/features.gni")
|
||||
import("//build/ohos.gni")
|
||||
import("//build/test.gni")
|
||||
import("//foundation/ability/ability_runtime/ability_runtime.gni")
|
||||
module_output_path = "ability_runtime/abilitymgr"
|
||||
|
||||
##############################fuzztest##########################################
|
||||
ohos_fuzztest("AbilityInterfacesAppManagerAmsMgrStubFuzzTest") {
|
||||
module_out_path = module_output_path
|
||||
|
||||
cflags_cc = []
|
||||
fuzz_config_file = "${ability_runtime_test_path}/fuzztest/abilityinterfacesappmanageramsmgrstub_fuzzer"
|
||||
include_dirs = [ "${ability_runtime_services_path}/appmgr/include" ]
|
||||
cflags = [
|
||||
"-g",
|
||||
"-O0",
|
||||
"-Wno-unused-variable",
|
||||
"-fno-omit-frame-pointer",
|
||||
]
|
||||
sources = [ "abilityinterfacesappmanageramsmgrstub_fuzzer.cpp" ]
|
||||
|
||||
configs = [ "${ability_runtime_services_path}/abilitymgr:abilityms_config" ]
|
||||
|
||||
cflags = []
|
||||
if (target_cpu == "arm") {
|
||||
cflags += [ "-DBINDER_IPC_32BIT" ]
|
||||
}
|
||||
|
||||
deps = [
|
||||
"${ability_runtime_innerkits_path}/app_manager:app_manager",
|
||||
"${ability_runtime_native_path}/ability/native:abilitykit_native",
|
||||
"${ability_runtime_services_path}/abilitymgr:abilityms",
|
||||
"${ability_runtime_services_path}/appmgr:libappms",
|
||||
"${ability_runtime_services_path}/common:perm_verification",
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
"ability_base:session_info",
|
||||
"ability_base:want",
|
||||
"ability_base:zuri",
|
||||
"appspawn:appspawn_client",
|
||||
"bundle_framework:appexecfwk_base",
|
||||
"bundle_framework:appexecfwk_core",
|
||||
"c_utils:utils",
|
||||
"common_event_service:cesfwk_innerkits",
|
||||
"ffrt:libffrt",
|
||||
"init:libbegetutil",
|
||||
"ipc:ipc_core",
|
||||
"napi:ace_napi",
|
||||
"safwk:system_ability_fwk",
|
||||
"samgr:samgr_proxy",
|
||||
]
|
||||
|
||||
if (ability_runtime_graphics) {
|
||||
external_deps += [ "input:libmmi-client" ]
|
||||
}
|
||||
}
|
||||
|
||||
###############################################################################
|
||||
group("fuzztest") {
|
||||
testonly = true
|
||||
deps = []
|
||||
deps += [
|
||||
# deps file
|
||||
":AbilityInterfacesAppManagerAmsMgrStubFuzzTest",
|
||||
]
|
||||
}
|
||||
###############################################################################
|
||||
+118
@@ -0,0 +1,118 @@
|
||||
/*
|
||||
* Copyright (c) 2024 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "abilityinterfacesappmanageramsmgrstub_fuzzer.h"
|
||||
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
|
||||
#define private public
|
||||
#include "ams_mgr_stub.h"
|
||||
#include "ams_mgr_scheduler.h"
|
||||
#undef private
|
||||
|
||||
#include "securec.h"
|
||||
#include "parcel.h"
|
||||
#include "ability_record.h"
|
||||
|
||||
using namespace OHOS::AAFwk;
|
||||
using namespace OHOS::AppExecFwk;
|
||||
|
||||
namespace OHOS {
|
||||
namespace {
|
||||
constexpr int INPUT_ZERO = 0;
|
||||
constexpr int INPUT_ONE = 1;
|
||||
constexpr int INPUT_TWO = 2;
|
||||
constexpr int INPUT_THREE = 3;
|
||||
constexpr size_t FOO_MAX_LEN = 1024;
|
||||
constexpr size_t U32_AT_SIZE = 4;
|
||||
constexpr size_t OFFSET_ZERO = 24;
|
||||
constexpr size_t OFFSET_ONE = 16;
|
||||
constexpr size_t OFFSET_TWO = 8;
|
||||
constexpr uint8_t ENABLE = 2;
|
||||
}
|
||||
const std::u16string AMSMGR_INTERFACE_TOKEN = u"ohos.appexecfwk.IAmsMgr";
|
||||
uint32_t GetU32Data(const char* ptr)
|
||||
{
|
||||
// convert fuzz input data to an integer
|
||||
return (ptr[INPUT_ZERO] << OFFSET_ZERO) | (ptr[INPUT_ONE] << OFFSET_ONE) | (ptr[INPUT_TWO] << OFFSET_TWO) |
|
||||
ptr[INPUT_THREE];
|
||||
}
|
||||
|
||||
sptr<Token> GetFuzzAbilityToken()
|
||||
{
|
||||
sptr<Token> token = nullptr;
|
||||
AbilityRequest abilityRequest;
|
||||
abilityRequest.appInfo.bundleName = "com.example.fuzzTest";
|
||||
abilityRequest.abilityInfo.name = "MainAbility";
|
||||
abilityRequest.abilityInfo.type = AbilityType::DATA;
|
||||
std::shared_ptr<AbilityRecord> abilityRecord = AbilityRecord::CreateAbilityRecord(abilityRequest);
|
||||
if (abilityRecord) {
|
||||
token = abilityRecord->GetToken();
|
||||
}
|
||||
return token;
|
||||
}
|
||||
|
||||
bool DoSomethingInterestingWithMyAPI(const char* data, size_t size)
|
||||
{
|
||||
uint32_t code = static_cast<uint32_t>(IAmsMgr::Message::UPDATE_EXTENSION_STATE);
|
||||
MessageParcel parcel;
|
||||
parcel.WriteInterfaceToken(AMSMGR_INTERFACE_TOKEN);
|
||||
parcel.WriteBuffer(data, size);
|
||||
parcel.RewindRead(0);
|
||||
MessageParcel reply;
|
||||
MessageOption option;
|
||||
std::shared_ptr<AppMgrServiceInner> MgrServiceInner;
|
||||
std::shared_ptr<AAFwk::TaskHandlerWrap> Handler;
|
||||
std::shared_ptr<AmsMgrScheduler> abms = std::make_shared<AmsMgrScheduler>(MgrServiceInner, Handler);
|
||||
abms->OnRemoteRequest(code, parcel, reply, option);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/* Fuzzer entry point */
|
||||
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
|
||||
{
|
||||
/* Run your code on data */
|
||||
if (data == nullptr) {
|
||||
std::cout << "invalid data" << std::endl;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Validate the length of size */
|
||||
if (size > OHOS::FOO_MAX_LEN || size < OHOS::U32_AT_SIZE) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
char* ch = (char*)malloc(size + 1);
|
||||
if (ch == nullptr) {
|
||||
std::cout << "malloc failed." << std::endl;
|
||||
return 0;
|
||||
}
|
||||
|
||||
(void)memset_s(ch, size + 1, 0x00, size + 1);
|
||||
if (memcpy_s(ch, size + 1, data, size) != EOK) {
|
||||
std::cout << "copy failed." << std::endl;
|
||||
free(ch);
|
||||
ch = nullptr;
|
||||
return 0;
|
||||
}
|
||||
|
||||
OHOS::DoSomethingInterestingWithMyAPI(ch, size);
|
||||
free(ch);
|
||||
ch = nullptr;
|
||||
return 0;
|
||||
}
|
||||
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
/*
|
||||
* Copyright (c) 2024 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef FUZZTEST_OHOS_ABILITY_RUNTIME_ABILITYINTERFACESAPPMANGERAMSMGRSTUB_FUZZER_H
|
||||
#define FUZZTEST_OHOS_ABILITY_RUNTIME_ABILITYINTERFACESAPPMANGERAMSMGRSTUB_FUZZER_H
|
||||
|
||||
#define FUZZ_PROJECT_NAME "abilityinterfacesappmanageramsmgrstub_fuzzer"
|
||||
|
||||
#endif // FUZZTEST_OHOS_ABILITY_RUNTIME_ABILITYINTERFACESAPPMANGERAMSMGRSTUB_FUZZER_H
|
||||
@@ -0,0 +1,16 @@
|
||||
/*
|
||||
* Copyright (c) 2024 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
FUZZ
|
||||
@@ -0,0 +1,25 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Copyright (c) 2024 Huawei Device Co., Ltd.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
-->
|
||||
<fuzz_config>
|
||||
<fuzztest>
|
||||
<!-- maximum length of a test input -->
|
||||
<max_len>1000</max_len>
|
||||
<!-- maximum total time in seconds to run the fuzzer -->
|
||||
<max_total_time>300</max_total_time>
|
||||
<!-- memory usage limit in Mb -->
|
||||
<rss_limit_mb>4096</rss_limit_mb>
|
||||
</fuzztest>
|
||||
</fuzz_config>
|
||||
@@ -0,0 +1,82 @@
|
||||
# Copyright (c) 2024 Huawei Device Co., Ltd.
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
#####################hydra-fuzz###################
|
||||
import("//build/config/features.gni")
|
||||
import("//build/ohos.gni")
|
||||
import("//build/test.gni")
|
||||
import("//foundation/ability/ability_runtime/ability_runtime.gni")
|
||||
module_output_path = "ability_runtime/abilitymgr"
|
||||
|
||||
##############################fuzztest##########################################
|
||||
ohos_fuzztest("AbilityInterfacesAppMgrAbilityDebugResponseProxyFuzzTest") {
|
||||
module_out_path = module_output_path
|
||||
|
||||
cflags_cc = []
|
||||
fuzz_config_file = "${ability_runtime_test_path}/fuzztest/abilityinterfacesappmgrabilitydebugresponseproxy_fuzzer"
|
||||
include_dirs = [ "${ability_runtime_services_path}/appmgr/include" ]
|
||||
cflags = [
|
||||
"-g",
|
||||
"-O0",
|
||||
"-Wno-unused-variable",
|
||||
"-fno-omit-frame-pointer",
|
||||
]
|
||||
sources = [ "abilityinterfacesappmgrabilitydebugresponseproxy_fuzzer.cpp" ]
|
||||
|
||||
configs = [ "${ability_runtime_services_path}/abilitymgr:abilityms_config" ]
|
||||
|
||||
cflags = []
|
||||
if (target_cpu == "arm") {
|
||||
cflags += [ "-DBINDER_IPC_32BIT" ]
|
||||
}
|
||||
|
||||
deps = [
|
||||
"${ability_runtime_innerkits_path}/app_manager:app_manager",
|
||||
"${ability_runtime_native_path}/ability/native:abilitykit_native",
|
||||
"${ability_runtime_services_path}/abilitymgr:abilityms",
|
||||
"${ability_runtime_services_path}/appmgr:libappms",
|
||||
"${ability_runtime_services_path}/common:perm_verification",
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
"ability_base:session_info",
|
||||
"ability_base:want",
|
||||
"ability_base:zuri",
|
||||
"appspawn:appspawn_client",
|
||||
"bundle_framework:appexecfwk_base",
|
||||
"bundle_framework:appexecfwk_core",
|
||||
"c_utils:utils",
|
||||
"common_event_service:cesfwk_innerkits",
|
||||
"ffrt:libffrt",
|
||||
"init:libbegetutil",
|
||||
"ipc:ipc_core",
|
||||
"napi:ace_napi",
|
||||
"safwk:system_ability_fwk",
|
||||
"samgr:samgr_proxy",
|
||||
]
|
||||
|
||||
if (ability_runtime_graphics) {
|
||||
external_deps += [ "input:libmmi-client" ]
|
||||
}
|
||||
}
|
||||
|
||||
###############################################################################
|
||||
group("fuzztest") {
|
||||
testonly = true
|
||||
deps = []
|
||||
deps += [
|
||||
# deps file
|
||||
":AbilityInterfacesAppMgrAbilityDebugResponseProxyFuzzTest",
|
||||
]
|
||||
}
|
||||
###############################################################################
|
||||
+125
@@ -0,0 +1,125 @@
|
||||
/*
|
||||
* Copyright (c) 2024 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "abilityinterfacesappmgrabilitydebugresponseproxy_fuzzer.h"
|
||||
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
|
||||
#define private public
|
||||
#include "ability_debug_response_proxy.h"
|
||||
#include "ability_debug_response_interface.h"
|
||||
#undef private
|
||||
|
||||
#include "securec.h"
|
||||
#include "parcel.h"
|
||||
#include "ability_record.h"
|
||||
|
||||
using namespace OHOS::AAFwk;
|
||||
using namespace OHOS::AppExecFwk;
|
||||
|
||||
namespace OHOS {
|
||||
namespace {
|
||||
constexpr int INPUT_ZERO = 0;
|
||||
constexpr int INPUT_ONE = 1;
|
||||
constexpr int INPUT_TWO = 2;
|
||||
constexpr int INPUT_THREE = 3;
|
||||
constexpr size_t FOO_MAX_LEN = 1024;
|
||||
constexpr size_t U32_AT_SIZE = 4;
|
||||
constexpr size_t OFFSET_ZERO = 24;
|
||||
constexpr size_t OFFSET_ONE = 16;
|
||||
constexpr size_t OFFSET_TWO = 8;
|
||||
constexpr uint8_t ENABLE = 2;
|
||||
}
|
||||
const std::u16string AMSMGR_INTERFACE_TOKEN = u"ohos.appexecfwk.IAmsMgr";
|
||||
uint32_t GetU32Data(const char* ptr)
|
||||
{
|
||||
// convert fuzz input data to an integer
|
||||
return (ptr[INPUT_ZERO] << OFFSET_ZERO) | (ptr[INPUT_ONE] << OFFSET_ONE) | (ptr[INPUT_TWO] << OFFSET_TWO) |
|
||||
ptr[INPUT_THREE];
|
||||
}
|
||||
|
||||
sptr<Token> GetFuzzAbilityToken()
|
||||
{
|
||||
sptr<Token> token = nullptr;
|
||||
AbilityRequest abilityRequest;
|
||||
abilityRequest.appInfo.bundleName = "com.example.fuzzTest";
|
||||
abilityRequest.abilityInfo.name = "MainAbility";
|
||||
abilityRequest.abilityInfo.type = AbilityType::DATA;
|
||||
std::shared_ptr<AbilityRecord> abilityRecord = AbilityRecord::CreateAbilityRecord(abilityRequest);
|
||||
if (abilityRecord) {
|
||||
token = abilityRecord->GetToken();
|
||||
}
|
||||
return token;
|
||||
}
|
||||
|
||||
bool DoSomethingInterestingWithMyAPI(const char* data, size_t size)
|
||||
{
|
||||
sptr<IRemoteObject> impl;
|
||||
std::shared_ptr<AbilityDebugResponseProxy> infosProxy = std::make_shared<AbilityDebugResponseProxy>(impl);
|
||||
std::vector<sptr<IRemoteObject>> tokens;
|
||||
infosProxy->OnAbilitysDebugStarted(tokens);
|
||||
infosProxy->OnAbilitysDebugStoped(tokens);
|
||||
bool isAssertDebug = *data % ENABLE;
|
||||
infosProxy->OnAbilitysAssertDebugChange(tokens, isAssertDebug);
|
||||
MessageParcel parcels;
|
||||
parcels.WriteInterfaceToken(AMSMGR_INTERFACE_TOKEN);
|
||||
parcels.WriteBuffer(data, size);
|
||||
parcels.RewindRead(0);
|
||||
infosProxy->WriteInterfaceToken(parcels);
|
||||
IAbilityDebugResponse::Message message = IAbilityDebugResponse::Message::ON_ABILITYS_DEBUG_STARTED;
|
||||
infosProxy->SendRequest(message, tokens);
|
||||
message = IAbilityDebugResponse::Message::ON_ABILITYS_DEBUG_STOPED;
|
||||
infosProxy->SendRequest(message, tokens);
|
||||
message = IAbilityDebugResponse::Message::ON_ABILITYS_ASSERT_DEBUG;
|
||||
infosProxy->SendRequest(message, tokens);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/* Fuzzer entry point */
|
||||
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
|
||||
{
|
||||
/* Run your code on data */
|
||||
if (data == nullptr) {
|
||||
std::cout << "invalid data" << std::endl;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Validate the length of size */
|
||||
if (size > OHOS::FOO_MAX_LEN || size < OHOS::U32_AT_SIZE) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
char* ch = (char*)malloc(size + 1);
|
||||
if (ch == nullptr) {
|
||||
std::cout << "malloc failed." << std::endl;
|
||||
return 0;
|
||||
}
|
||||
|
||||
(void)memset_s(ch, size + 1, 0x00, size + 1);
|
||||
if (memcpy_s(ch, size + 1, data, size) != EOK) {
|
||||
std::cout << "copy failed." << std::endl;
|
||||
free(ch);
|
||||
ch = nullptr;
|
||||
return 0;
|
||||
}
|
||||
|
||||
OHOS::DoSomethingInterestingWithMyAPI(ch, size);
|
||||
free(ch);
|
||||
ch = nullptr;
|
||||
return 0;
|
||||
}
|
||||
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
/*
|
||||
* Copyright (c) 2024 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef FUZZTEST_OHOS_ABILITY_RUNTIME_ABILITYINTERFACESAPPMGRAPPDEBUGLISTTENERPROXY_FUZZER_H
|
||||
#define FUZZTEST_OHOS_ABILITY_RUNTIME_ABILITYINTERFACESAPPMGRAPPDEBUGLISTTENERPROXY_FUZZER_H
|
||||
|
||||
#define FUZZ_PROJECT_NAME "abilityinterfacesappmgrappdebuglistenerproxy_fuzzer"
|
||||
|
||||
#endif // FUZZTEST_OHOS_ABILITY_RUNTIME_ABILITYINTERFACESAPPMGRAPPDEBUGLISTTENERPROXY_FUZZER_H
|
||||
@@ -0,0 +1,16 @@
|
||||
/*
|
||||
* Copyright (c) 2024 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
FUZZ
|
||||
@@ -0,0 +1,25 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Copyright (c) 2024 Huawei Device Co., Ltd.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
-->
|
||||
<fuzz_config>
|
||||
<fuzztest>
|
||||
<!-- maximum length of a test input -->
|
||||
<max_len>1000</max_len>
|
||||
<!-- maximum total time in seconds to run the fuzzer -->
|
||||
<max_total_time>300</max_total_time>
|
||||
<!-- memory usage limit in Mb -->
|
||||
<rss_limit_mb>4096</rss_limit_mb>
|
||||
</fuzztest>
|
||||
</fuzz_config>
|
||||
@@ -0,0 +1,82 @@
|
||||
# Copyright (c) 2024 Huawei Device Co., Ltd.
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
#####################hydra-fuzz###################
|
||||
import("//build/config/features.gni")
|
||||
import("//build/ohos.gni")
|
||||
import("//build/test.gni")
|
||||
import("//foundation/ability/ability_runtime/ability_runtime.gni")
|
||||
module_output_path = "ability_runtime/abilitymgr"
|
||||
|
||||
##############################fuzztest##########################################
|
||||
ohos_fuzztest("AbilityInterfacesAppMgrAppDebugListenerProxyFuzzTest") {
|
||||
module_out_path = module_output_path
|
||||
|
||||
cflags_cc = []
|
||||
fuzz_config_file = "${ability_runtime_test_path}/fuzztest/abilityinterfacesappmgrappdebuglistenerproxy_fuzzer"
|
||||
include_dirs = [ "${ability_runtime_services_path}/appmgr/include" ]
|
||||
cflags = [
|
||||
"-g",
|
||||
"-O0",
|
||||
"-Wno-unused-variable",
|
||||
"-fno-omit-frame-pointer",
|
||||
]
|
||||
sources = [ "abilityinterfacesappmgrappdebuglistenerproxy_fuzzer.cpp" ]
|
||||
|
||||
configs = [ "${ability_runtime_services_path}/abilitymgr:abilityms_config" ]
|
||||
|
||||
cflags = []
|
||||
if (target_cpu == "arm") {
|
||||
cflags += [ "-DBINDER_IPC_32BIT" ]
|
||||
}
|
||||
|
||||
deps = [
|
||||
"${ability_runtime_innerkits_path}/app_manager:app_manager",
|
||||
"${ability_runtime_native_path}/ability/native:abilitykit_native",
|
||||
"${ability_runtime_services_path}/abilitymgr:abilityms",
|
||||
"${ability_runtime_services_path}/appmgr:libappms",
|
||||
"${ability_runtime_services_path}/common:perm_verification",
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
"ability_base:session_info",
|
||||
"ability_base:want",
|
||||
"ability_base:zuri",
|
||||
"appspawn:appspawn_client",
|
||||
"bundle_framework:appexecfwk_base",
|
||||
"bundle_framework:appexecfwk_core",
|
||||
"c_utils:utils",
|
||||
"common_event_service:cesfwk_innerkits",
|
||||
"ffrt:libffrt",
|
||||
"init:libbegetutil",
|
||||
"ipc:ipc_core",
|
||||
"napi:ace_napi",
|
||||
"safwk:system_ability_fwk",
|
||||
"samgr:samgr_proxy",
|
||||
]
|
||||
|
||||
if (ability_runtime_graphics) {
|
||||
external_deps += [ "input:libmmi-client" ]
|
||||
}
|
||||
}
|
||||
|
||||
###############################################################################
|
||||
group("fuzztest") {
|
||||
testonly = true
|
||||
deps = []
|
||||
deps += [
|
||||
# deps file
|
||||
":AbilityInterfacesAppMgrAppDebugListenerProxyFuzzTest",
|
||||
]
|
||||
}
|
||||
###############################################################################
|
||||
+121
@@ -0,0 +1,121 @@
|
||||
/*
|
||||
* Copyright (c) 2024 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "abilityinterfacesappmgrappdebuglistenerproxy_fuzzer.h"
|
||||
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
|
||||
#define private public
|
||||
#include "app_debug_listener_proxy.h"
|
||||
#include "app_debug_listener_interface.h"
|
||||
#undef private
|
||||
|
||||
#include "securec.h"
|
||||
#include "parcel.h"
|
||||
#include "ability_record.h"
|
||||
|
||||
using namespace OHOS::AAFwk;
|
||||
using namespace OHOS::AppExecFwk;
|
||||
|
||||
namespace OHOS {
|
||||
namespace {
|
||||
constexpr int INPUT_ZERO = 0;
|
||||
constexpr int INPUT_ONE = 1;
|
||||
constexpr int INPUT_TWO = 2;
|
||||
constexpr int INPUT_THREE = 3;
|
||||
constexpr size_t FOO_MAX_LEN = 1024;
|
||||
constexpr size_t U32_AT_SIZE = 4;
|
||||
constexpr size_t OFFSET_ZERO = 24;
|
||||
constexpr size_t OFFSET_ONE = 16;
|
||||
constexpr size_t OFFSET_TWO = 8;
|
||||
constexpr uint8_t ENABLE = 2;
|
||||
}
|
||||
const std::u16string AMSMGR_INTERFACE_TOKEN = u"ohos.appexecfwk.IAmsMgr";
|
||||
uint32_t GetU32Data(const char* ptr)
|
||||
{
|
||||
// convert fuzz input data to an integer
|
||||
return (ptr[INPUT_ZERO] << OFFSET_ZERO) | (ptr[INPUT_ONE] << OFFSET_ONE) | (ptr[INPUT_TWO] << OFFSET_TWO) |
|
||||
ptr[INPUT_THREE];
|
||||
}
|
||||
|
||||
sptr<Token> GetFuzzAbilityToken()
|
||||
{
|
||||
sptr<Token> token = nullptr;
|
||||
AbilityRequest abilityRequest;
|
||||
abilityRequest.appInfo.bundleName = "com.example.fuzzTest";
|
||||
abilityRequest.abilityInfo.name = "MainAbility";
|
||||
abilityRequest.abilityInfo.type = AbilityType::DATA;
|
||||
std::shared_ptr<AbilityRecord> abilityRecord = AbilityRecord::CreateAbilityRecord(abilityRequest);
|
||||
if (abilityRecord) {
|
||||
token = abilityRecord->GetToken();
|
||||
}
|
||||
return token;
|
||||
}
|
||||
|
||||
bool DoSomethingInterestingWithMyAPI(const char* data, size_t size)
|
||||
{
|
||||
sptr<IRemoteObject> impl;
|
||||
std::shared_ptr<AppDebugListenerProxy> infosProxy = std::make_shared<AppDebugListenerProxy>(impl);
|
||||
std::vector<AppDebugInfo> debugInfos;
|
||||
infosProxy->OnAppDebugStarted(debugInfos);
|
||||
infosProxy->OnAppDebugStoped(debugInfos);
|
||||
MessageParcel parcels;
|
||||
parcels.WriteInterfaceToken(AMSMGR_INTERFACE_TOKEN);
|
||||
parcels.WriteBuffer(data, size);
|
||||
parcels.RewindRead(0);
|
||||
infosProxy->WriteInterfaceToken(parcels);
|
||||
IAppDebugListener::Message message = IAppDebugListener::Message::ON_APP_DEBUG_STARTED;
|
||||
infosProxy->SendRequest(message, debugInfos);
|
||||
message = IAppDebugListener::Message::ON_APP_DEBUG_STOPED;
|
||||
infosProxy->SendRequest(message, debugInfos);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/* Fuzzer entry point */
|
||||
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
|
||||
{
|
||||
/* Run your code on data */
|
||||
if (data == nullptr) {
|
||||
std::cout << "invalid data" << std::endl;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Validate the length of size */
|
||||
if (size > OHOS::FOO_MAX_LEN || size < OHOS::U32_AT_SIZE) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
char* ch = (char*)malloc(size + 1);
|
||||
if (ch == nullptr) {
|
||||
std::cout << "malloc failed." << std::endl;
|
||||
return 0;
|
||||
}
|
||||
|
||||
(void)memset_s(ch, size + 1, 0x00, size + 1);
|
||||
if (memcpy_s(ch, size + 1, data, size) != EOK) {
|
||||
std::cout << "copy failed." << std::endl;
|
||||
free(ch);
|
||||
ch = nullptr;
|
||||
return 0;
|
||||
}
|
||||
|
||||
OHOS::DoSomethingInterestingWithMyAPI(ch, size);
|
||||
free(ch);
|
||||
ch = nullptr;
|
||||
return 0;
|
||||
}
|
||||
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
/*
|
||||
* Copyright (c) 2024 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef FUZZTEST_OHOS_ABILITY_RUNTIME_ABILITYINTERFACESAPPMGRAPPDEBUGLISTTENERPROXY_FUZZER_H
|
||||
#define FUZZTEST_OHOS_ABILITY_RUNTIME_ABILITYINTERFACESAPPMGRAPPDEBUGLISTTENERPROXY_FUZZER_H
|
||||
|
||||
#define FUZZ_PROJECT_NAME "abilityinterfacesappmgrappdebuglistenerproxy_fuzzer"
|
||||
|
||||
#endif // FUZZTEST_OHOS_ABILITY_RUNTIME_ABILITYINTERFACESAPPMGRAPPDEBUGLISTTENERPROXY_FUZZER_H
|
||||
@@ -0,0 +1,16 @@
|
||||
/*
|
||||
* Copyright (c) 2024 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
FUZZ
|
||||
@@ -0,0 +1,25 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Copyright (c) 2024 Huawei Device Co., Ltd.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
-->
|
||||
<fuzz_config>
|
||||
<fuzztest>
|
||||
<!-- maximum length of a test input -->
|
||||
<max_len>1000</max_len>
|
||||
<!-- maximum total time in seconds to run the fuzzer -->
|
||||
<max_total_time>300</max_total_time>
|
||||
<!-- memory usage limit in Mb -->
|
||||
<rss_limit_mb>4096</rss_limit_mb>
|
||||
</fuzztest>
|
||||
</fuzz_config>
|
||||
@@ -0,0 +1,102 @@
|
||||
# Copyright (c) 2024 Huawei Device Co., Ltd.
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
#####################hydra-fuzz###################
|
||||
import("//build/config/features.gni")
|
||||
import("//build/ohos.gni")
|
||||
import("//build/test.gni")
|
||||
import("//foundation/ability/ability_runtime/ability_runtime.gni")
|
||||
module_output_path = "ability_runtime/abilitymgr"
|
||||
|
||||
##############################fuzztest##########################################
|
||||
ohos_fuzztest("AbilityMgrAbilityManagerStubFuzzTest") {
|
||||
module_out_path = module_output_path
|
||||
|
||||
cflags_cc = []
|
||||
fuzz_config_file = "${ability_runtime_test_path}/fuzztest/abilitymgrabilitymanagerstub_fuzzer"
|
||||
include_dirs = [
|
||||
"${ability_runtime_path}/interfaces/kits/native/appkit/ability_bundle_manager_helper",
|
||||
"${ability_runtime_innerkits_path}/app_manager/include/appmgr",
|
||||
"${ability_runtime_services_path}/abilitymgr/include",
|
||||
"${ability_runtime_services_path}/common/include",
|
||||
"${ability_runtime_path}/interfaces/kits/native/session_info/include",
|
||||
"${distributedschedule_path}/samgr/adapter/interfaces/innerkits/include",
|
||||
"${distributedschedule_path}/samgr/interfaces/innerkits/samgr_proxy/include",
|
||||
"${distributedschedule_path}/samgr/utils/native/include",
|
||||
]
|
||||
cflags = [
|
||||
"-g",
|
||||
"-O0",
|
||||
"-Wno-unused-variable",
|
||||
"-fno-omit-frame-pointer",
|
||||
]
|
||||
sources = [ "abilitymgrabilitymanagerstub_fuzzer.cpp" ]
|
||||
|
||||
configs = [ "${ability_runtime_services_path}/abilitymgr:abilityms_config" ]
|
||||
|
||||
cflags = []
|
||||
if (target_cpu == "arm") {
|
||||
cflags += [ "-DBINDER_IPC_32BIT" ]
|
||||
}
|
||||
|
||||
deps = [
|
||||
"${ability_runtime_innerkits_path}/ability_manager:ability_manager",
|
||||
"${ability_runtime_innerkits_path}/ability_manager:ability_start_options",
|
||||
"${ability_runtime_innerkits_path}/ability_manager:mission_info",
|
||||
"${ability_runtime_innerkits_path}/app_manager:app_manager",
|
||||
"${ability_runtime_native_path}/ability/native:abilitykit_native",
|
||||
"${ability_runtime_native_path}/appkit:appkit_manager_helper",
|
||||
"${ability_runtime_path}/utils/server/startup:startup_util",
|
||||
"${ability_runtime_services_path}/abilitymgr:abilityms",
|
||||
"${ability_runtime_services_path}/common:perm_verification",
|
||||
"${ability_runtime_services_path}/common:task_handler_wrap",
|
||||
"//third_party/jsoncpp:jsoncpp",
|
||||
"//third_party/libjpeg-turbo:turbojpeg_static",
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
"ability_base:want",
|
||||
"ability_base:zuri",
|
||||
"ability_runtime:ability_deps_wrapper",
|
||||
"ability_runtime:ability_manager",
|
||||
"access_token:libaccesstoken_sdk",
|
||||
"c_utils:utils",
|
||||
"common_event_service:cesfwk_innerkits",
|
||||
"dsoftbus:softbus_client",
|
||||
"ffrt:libffrt",
|
||||
"hilog:libhilog",
|
||||
"hitrace:hitrace_meter",
|
||||
"init:libbeget_proxy",
|
||||
"ipc:ipc_core",
|
||||
"napi:ace_napi",
|
||||
]
|
||||
|
||||
if (background_task_mgr_continuous_task_enable) {
|
||||
external_deps += [ "background_task_mgr:bgtaskmgr_innerkits" ]
|
||||
}
|
||||
|
||||
if (ability_runtime_graphics) {
|
||||
external_deps += [ "window_manager:libwm" ]
|
||||
}
|
||||
}
|
||||
|
||||
###############################################################################
|
||||
group("fuzztest") {
|
||||
testonly = true
|
||||
deps = []
|
||||
deps += [
|
||||
# deps file
|
||||
":AbilityMgrAbilityManagerStubFuzzTest",
|
||||
]
|
||||
}
|
||||
###############################################################################
|
||||
+122
@@ -0,0 +1,122 @@
|
||||
/*
|
||||
* Copyright (c) 2024 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "abilitymgrabilitymanagerstub_fuzzer.h"
|
||||
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
|
||||
#define private public
|
||||
#include "ability_manager_service.h"
|
||||
#undef private
|
||||
|
||||
#include "securec.h"
|
||||
#include "ability_record.h"
|
||||
|
||||
using namespace OHOS::AAFwk;
|
||||
using namespace OHOS::AppExecFwk;
|
||||
|
||||
namespace OHOS {
|
||||
namespace {
|
||||
constexpr int INPUT_ZERO = 0;
|
||||
constexpr int INPUT_ONE = 1;
|
||||
constexpr int INPUT_TWO = 2;
|
||||
constexpr int INPUT_THREE = 3;
|
||||
constexpr size_t FOO_MAX_LEN = 1024;
|
||||
constexpr size_t U32_AT_SIZE = 4;
|
||||
constexpr size_t OFFSET_ZERO = 24;
|
||||
constexpr size_t OFFSET_ONE = 16;
|
||||
constexpr size_t OFFSET_TWO = 8;
|
||||
constexpr uint8_t ENABLE = 2;
|
||||
}
|
||||
const std::u16string ABILITYMGR_INTERFACE_TOKEN = u"ohos.aafwk.AbilityManager";
|
||||
uint32_t GetU32Data(const char* ptr)
|
||||
{
|
||||
// convert fuzz input data to an integer
|
||||
return (ptr[INPUT_ZERO] << OFFSET_ZERO) | (ptr[INPUT_ONE] << OFFSET_ONE) | (ptr[INPUT_TWO] << OFFSET_TWO) |
|
||||
ptr[INPUT_THREE];
|
||||
}
|
||||
|
||||
sptr<Token> GetFuzzAbilityToken()
|
||||
{
|
||||
sptr<Token> token = nullptr;
|
||||
AbilityRequest abilityRequest;
|
||||
abilityRequest.appInfo.bundleName = "com.example.fuzzTest";
|
||||
abilityRequest.abilityInfo.name = "MainAbility";
|
||||
abilityRequest.abilityInfo.type = AbilityType::DATA;
|
||||
std::shared_ptr<AbilityRecord> abilityRecord = AbilityRecord::CreateAbilityRecord(abilityRequest);
|
||||
if (abilityRecord) {
|
||||
token = abilityRecord->GetToken();
|
||||
}
|
||||
return token;
|
||||
}
|
||||
|
||||
bool DoSomethingInterestingWithMyAPI(const char* data, size_t size)
|
||||
{
|
||||
uint32_t codeOne = static_cast<uint32_t>(AbilityManagerInterfaceCode::GET_PENDING_WANT_TYPE);
|
||||
MessageParcel parcel;
|
||||
parcel.WriteInterfaceToken(ABILITYMGR_INTERFACE_TOKEN);
|
||||
parcel.WriteBuffer(data, size);
|
||||
parcel.RewindRead(0);
|
||||
MessageParcel reply;
|
||||
MessageOption option;
|
||||
std::shared_ptr<AbilityManagerService> abmsOne = std::make_shared<AbilityManagerService>();
|
||||
abmsOne->OnRemoteRequest(codeOne, parcel, reply, option);
|
||||
|
||||
uint32_t codeTwo = static_cast<uint32_t>(AbilityManagerInterfaceCode::START_UI_EXTENSION_ABILITY);
|
||||
MessageParcel parcels;
|
||||
parcels.WriteInterfaceToken(ABILITYMGR_INTERFACE_TOKEN);
|
||||
parcels.WriteBuffer(data, size);
|
||||
parcels.RewindRead(0);
|
||||
std::shared_ptr<AbilityManagerService> abmsTwo = std::make_shared<AbilityManagerService>();
|
||||
abmsTwo->OnRemoteRequest(codeTwo, parcels, reply, option);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/* Fuzzer entry point */
|
||||
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
|
||||
{
|
||||
/* Run your code on data */
|
||||
if (data == nullptr) {
|
||||
std::cout << "invalid data" << std::endl;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Validate the length of size */
|
||||
if (size > OHOS::FOO_MAX_LEN || size < OHOS::U32_AT_SIZE) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
char* ch = (char*)malloc(size + 1);
|
||||
if (ch == nullptr) {
|
||||
std::cout << "malloc failed." << std::endl;
|
||||
return 0;
|
||||
}
|
||||
|
||||
(void)memset_s(ch, size + 1, 0x00, size + 1);
|
||||
if (memcpy_s(ch, size + 1, data, size) != EOK) {
|
||||
std::cout << "copy failed." << std::endl;
|
||||
free(ch);
|
||||
ch = nullptr;
|
||||
return 0;
|
||||
}
|
||||
|
||||
OHOS::DoSomethingInterestingWithMyAPI(ch, size);
|
||||
free(ch);
|
||||
ch = nullptr;
|
||||
return 0;
|
||||
}
|
||||
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
/*
|
||||
* Copyright (c) 2024 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef FUZZTEST_OHOS_ABILITY_RUNTIME_ABILITYMGRABILITYMANAGERSTUB_FUZZER_H
|
||||
#define FUZZTEST_OHOS_ABILITY_RUNTIME_ABILITYMGRABILITYMANAGERSTUB_FUZZER_H
|
||||
|
||||
#define FUZZ_PROJECT_NAME "abilitymgrabilitymanagerstub_fuzzer"
|
||||
|
||||
#endif // FUZZTEST_OHOS_ABILITY_RUNTIME_ABILITYMGRABILITYMANAGERSTUB_FUZZER_H
|
||||
@@ -0,0 +1,16 @@
|
||||
/*
|
||||
* Copyright (c) 2024 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
FUZZ
|
||||
@@ -0,0 +1,25 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Copyright (c) 2024 Huawei Device Co., Ltd.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
-->
|
||||
<fuzz_config>
|
||||
<fuzztest>
|
||||
<!-- maximum length of a test input -->
|
||||
<max_len>1000</max_len>
|
||||
<!-- maximum total time in seconds to run the fuzzer -->
|
||||
<max_total_time>300</max_total_time>
|
||||
<!-- memory usage limit in Mb -->
|
||||
<rss_limit_mb>4096</rss_limit_mb>
|
||||
</fuzztest>
|
||||
</fuzz_config>
|
||||
@@ -0,0 +1,100 @@
|
||||
# Copyright (c) 2024 Huawei Device Co., Ltd.
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
#####################hydra-fuzz###################
|
||||
import("//build/config/features.gni")
|
||||
import("//build/ohos.gni")
|
||||
import("//build/test.gni")
|
||||
import("//foundation/ability/ability_runtime/ability_runtime.gni")
|
||||
module_output_path = "ability_runtime/abilitymgr"
|
||||
|
||||
##############################fuzztest##########################################
|
||||
ohos_fuzztest("AbilityMgrUiExtensionRecordFuzzTest") {
|
||||
module_out_path = module_output_path
|
||||
|
||||
cflags_cc = []
|
||||
fuzz_config_file =
|
||||
"${ability_runtime_test_path}/fuzztest/abilitymgruiextensionrecord_fuzzer"
|
||||
include_dirs = [
|
||||
"${ability_runtime_path}/interfaces/kits/native/appkit/ability_bundle_manager_helper",
|
||||
"${distributedschedule_path}/samgr/interfaces/innerkits/samgr_proxy/include",
|
||||
"${distributedschedule_path}/samgr/adapter/interfaces/innerkits/include/",
|
||||
"${ability_runtime_innerkits_path}/app_manager/include/appmgr",
|
||||
"${ability_runtime_services_path}/abilitymgr/include",
|
||||
]
|
||||
cflags = [
|
||||
"-g",
|
||||
"-O0",
|
||||
"-Wno-unused-variable",
|
||||
"-fno-omit-frame-pointer",
|
||||
]
|
||||
sources = [
|
||||
"${ability_runtime_services_path}/abilitymgr/src/extension_record.cpp",
|
||||
"${ability_runtime_services_path}/abilitymgr/src/preload_uiext_state_observer.cpp",
|
||||
"${ability_runtime_services_path}/abilitymgr/src/ui_extension_record.cpp",
|
||||
"abilitymgruiextensionrecord_fuzzer.cpp",
|
||||
]
|
||||
|
||||
configs = [ "${ability_runtime_services_path}/abilitymgr:abilityms_config" ]
|
||||
|
||||
cflags = []
|
||||
if (target_cpu == "arm") {
|
||||
cflags += [ "-DBINDER_IPC_32BIT" ]
|
||||
}
|
||||
|
||||
deps = [
|
||||
"${ability_runtime_innerkits_path}/ability_manager:ability_manager",
|
||||
"${ability_runtime_innerkits_path}/ability_manager:ability_start_options",
|
||||
"${ability_runtime_innerkits_path}/app_manager:app_manager",
|
||||
"${ability_runtime_native_path}/ability/native:abilitykit_native",
|
||||
"${ability_runtime_native_path}/appkit:appkit_manager_helper",
|
||||
"${ability_runtime_path}/utils/server/startup:startup_util",
|
||||
"${ability_runtime_services_path}/abilitymgr:abilityms",
|
||||
"${ability_runtime_services_path}/common:perm_verification",
|
||||
"//third_party/jsoncpp:jsoncpp",
|
||||
"//third_party/libjpeg-turbo:turbojpeg_static",
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
"ability_base:want",
|
||||
"ability_base:zuri",
|
||||
"ability_runtime:ability_deps_wrapper",
|
||||
"c_utils:utils",
|
||||
"common_event_service:cesfwk_innerkits",
|
||||
"dsoftbus:softbus_client",
|
||||
"ffrt:libffrt",
|
||||
"hilog:libhilog",
|
||||
"hitrace:hitrace_meter",
|
||||
"ipc:ipc_core",
|
||||
"napi:ace_napi",
|
||||
]
|
||||
|
||||
if (background_task_mgr_continuous_task_enable) {
|
||||
external_deps += [ "background_task_mgr:bgtaskmgr_innerkits" ]
|
||||
}
|
||||
|
||||
if (ability_runtime_graphics) {
|
||||
external_deps += [ "window_manager:libwm" ]
|
||||
}
|
||||
}
|
||||
|
||||
###############################################################################
|
||||
group("fuzztest") {
|
||||
testonly = true
|
||||
deps = []
|
||||
deps += [
|
||||
# deps file
|
||||
":AbilityMgrUiExtensionRecordFuzzTest",
|
||||
]
|
||||
}
|
||||
###############################################################################
|
||||
+121
@@ -0,0 +1,121 @@
|
||||
/*
|
||||
* Copyright (c) 2024 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "abilitymgruiextensionrecord_fuzzer.h"
|
||||
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
|
||||
#define private public
|
||||
#include "ui_extension_record.h"
|
||||
#undef private
|
||||
|
||||
#include "securec.h"
|
||||
#include "ability_record.h"
|
||||
|
||||
using namespace OHOS::AAFwk;
|
||||
using namespace OHOS::AppExecFwk;
|
||||
|
||||
namespace OHOS {
|
||||
namespace {
|
||||
constexpr int INPUT_ZERO = 0;
|
||||
constexpr int INPUT_ONE = 1;
|
||||
constexpr int INPUT_TWO = 2;
|
||||
constexpr int INPUT_THREE = 3;
|
||||
constexpr size_t FOO_MAX_LEN = 1024;
|
||||
constexpr size_t U32_AT_SIZE = 4;
|
||||
constexpr size_t OFFSET_ZERO = 24;
|
||||
constexpr size_t OFFSET_ONE = 16;
|
||||
constexpr size_t OFFSET_TWO = 8;
|
||||
constexpr uint8_t ENABLE = 2;
|
||||
}
|
||||
uint32_t GetU32Data(const char* ptr)
|
||||
{
|
||||
// convert fuzz input data to an integer
|
||||
return (ptr[INPUT_ZERO] << OFFSET_ZERO) | (ptr[INPUT_ONE] << OFFSET_ONE) | (ptr[INPUT_TWO] << OFFSET_TWO) |
|
||||
ptr[INPUT_THREE];
|
||||
}
|
||||
|
||||
sptr<Token> GetFuzzAbilityToken()
|
||||
{
|
||||
sptr<Token> token = nullptr;
|
||||
AbilityRequest abilityRequest;
|
||||
abilityRequest.appInfo.bundleName = "com.example.fuzzTest";
|
||||
abilityRequest.abilityInfo.name = "MainAbility";
|
||||
abilityRequest.abilityInfo.type = AbilityType::DATA;
|
||||
std::shared_ptr<AbilityRecord> abilityRecord = AbilityRecord::CreateAbilityRecord(abilityRequest);
|
||||
if (abilityRecord) {
|
||||
token = abilityRecord->GetToken();
|
||||
}
|
||||
return token;
|
||||
}
|
||||
|
||||
bool DoSomethingInterestingWithMyAPI(const char* data, size_t size)
|
||||
{
|
||||
std::shared_ptr<AAFwk::AbilityRecord> abilityRecord;
|
||||
AbilityRuntime::UIExtensionRecord infos(abilityRecord);
|
||||
infos.ContinueToGetCallerToken();
|
||||
AAFwk::AbilityRequest abilityRequest;
|
||||
infos.Update(abilityRequest);
|
||||
infos.LoadTimeout();
|
||||
infos.ForegroundTimeout();
|
||||
infos.BackgroundTimeout();
|
||||
infos.TerminateTimeout();
|
||||
AbilityRuntime::UIExtensionRecord::ErrorCode code = AbilityRuntime::UIExtensionRecord::ErrorCode::LOAD_TIMEOUT;
|
||||
infos.HandleNotifyUIExtensionTimeout(code);
|
||||
code = AbilityRuntime::UIExtensionRecord::ErrorCode::FOREGROUND_TIMEOUT;
|
||||
infos.HandleNotifyUIExtensionTimeout(code);
|
||||
code = AbilityRuntime::UIExtensionRecord::ErrorCode::BACKGROUND_TIMEOUT;
|
||||
infos.HandleNotifyUIExtensionTimeout(code);
|
||||
code = AbilityRuntime::UIExtensionRecord::ErrorCode::TERMINATE_TIMEOUT;
|
||||
infos.HandleNotifyUIExtensionTimeout(code);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/* Fuzzer entry point */
|
||||
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
|
||||
{
|
||||
/* Run your code on data */
|
||||
if (data == nullptr) {
|
||||
std::cout << "invalid data" << std::endl;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Validate the length of size */
|
||||
if (size > OHOS::FOO_MAX_LEN || size < OHOS::U32_AT_SIZE) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
char* ch = (char*)malloc(size + 1);
|
||||
if (ch == nullptr) {
|
||||
std::cout << "malloc failed." << std::endl;
|
||||
return 0;
|
||||
}
|
||||
|
||||
(void)memset_s(ch, size + 1, 0x00, size + 1);
|
||||
if (memcpy_s(ch, size + 1, data, size) != EOK) {
|
||||
std::cout << "copy failed." << std::endl;
|
||||
free(ch);
|
||||
ch = nullptr;
|
||||
return 0;
|
||||
}
|
||||
|
||||
OHOS::DoSomethingInterestingWithMyAPI(ch, size);
|
||||
free(ch);
|
||||
ch = nullptr;
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
/*
|
||||
* Copyright (c) 2024 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef FUZZTEST_OHOS_ABILITY_RUNTIME_ABILITYMGRUIEXTENSIONRECORD_FUZZER_H
|
||||
#define FUZZTEST_OHOS_ABILITY_RUNTIME_ABILITYMGRUIEXTENSIONRECORD_FUZZER_H
|
||||
|
||||
#define FUZZ_PROJECT_NAME "abilitymgruiextensionrecord_fuzzer"
|
||||
|
||||
#endif // FUZZTEST_OHOS_ABILITY_RUNTIME_ABILITYMGRUIEXTENSIONRECORD_FUZZER_H
|
||||
@@ -0,0 +1,16 @@
|
||||
/*
|
||||
* Copyright (c) 2024 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
FUZZ
|
||||
@@ -0,0 +1,25 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Copyright (c) 2024 Huawei Device Co., Ltd.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
-->
|
||||
<fuzz_config>
|
||||
<fuzztest>
|
||||
<!-- maximum length of a test input -->
|
||||
<max_len>1000</max_len>
|
||||
<!-- maximum total time in seconds to run the fuzzer -->
|
||||
<max_total_time>300</max_total_time>
|
||||
<!-- memory usage limit in Mb -->
|
||||
<rss_limit_mb>4096</rss_limit_mb>
|
||||
</fuzztest>
|
||||
</fuzz_config>
|
||||
Reference in New Issue
Block a user