mirror of
https://github.com/openharmony/ability_ability_runtime.git
synced 2026-08-25 12:23:20 -04:00
Issue:#I6WGUJ
Signed-off-by: zhoushicheng <zhoushicheng2@huawei.com> Change-Id: Id4bb3d91330d9e408d9ca54a6764f31e698ad1f2
This commit is contained in:
@@ -28,8 +28,8 @@ ohos_unittest("source_map_test") {
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
"ability_runtime:js_environment",
|
||||
"ability_base:want",
|
||||
"ability_runtime:js_environment",
|
||||
"bundle_framework:appexecfwk_base",
|
||||
"c_utils:utils",
|
||||
"eventhandler:libeventhandler",
|
||||
|
||||
@@ -57,6 +57,7 @@ group("fuzztest") {
|
||||
"abilitytransitiondone_fuzzer:fuzztest",
|
||||
"acquiredataability_fuzzer:fuzztest",
|
||||
"addabilitystagedone_fuzzer:fuzztest",
|
||||
"amsmanager_fuzzer:fuzztest",
|
||||
"amsmgrscheduler_fuzzer:fuzztest",
|
||||
"applicationanrlistener_fuzzer:fuzztest",
|
||||
"applifecycledeal_fuzzer:fuzztest",
|
||||
|
||||
@@ -0,0 +1,73 @@
|
||||
# Copyright (c) 2023 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/app_manager"
|
||||
|
||||
##############################fuzztest##########################################
|
||||
ohos_fuzztest("AmsManagerFuzzTest") {
|
||||
module_out_path = module_output_path
|
||||
|
||||
fuzz_config_file = "${ability_runtime_test_path}/fuzztest/amsmanager_fuzzer"
|
||||
include_dirs =
|
||||
[ "${ability_runtime_innerkits_path}/app_manager/include/appmgr" ]
|
||||
cflags = [
|
||||
"-g",
|
||||
"-O0",
|
||||
"-Wno-unused-variable",
|
||||
"-fno-omit-frame-pointer",
|
||||
]
|
||||
sources = [ "amsmanager_fuzzer.cpp" ]
|
||||
|
||||
configs = [ "${ability_runtime_services_path}/appmgr:appmgr_config" ]
|
||||
|
||||
deps = [
|
||||
"${ability_runtime_innerkits_path}/app_manager:app_manager",
|
||||
"${ability_runtime_services_path}/appmgr:libappms",
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
"ability_base:want",
|
||||
"ability_base:zuri",
|
||||
"bundle_framework:appexecfwk_base",
|
||||
"bundle_framework:appexecfwk_core",
|
||||
"c_utils:utils",
|
||||
"common_event_service:cesfwk_innerkits",
|
||||
"eventhandler:libeventhandler",
|
||||
"ipc:ipc_core",
|
||||
"safwk:system_ability_fwk",
|
||||
"samgr:samgr_proxy",
|
||||
]
|
||||
|
||||
if (ability_runtime_graphics) {
|
||||
external_deps += [
|
||||
"input:libmmi-client",
|
||||
"window_manager:libwm",
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
###############################################################################
|
||||
group("fuzztest") {
|
||||
testonly = true
|
||||
deps = []
|
||||
deps += [
|
||||
# deps file
|
||||
":AmsManagerFuzzTest",
|
||||
]
|
||||
}
|
||||
###############################################################################
|
||||
@@ -0,0 +1,97 @@
|
||||
/*
|
||||
* Copyright (c) 2023 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 "amsmanager_fuzzer.h"
|
||||
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
|
||||
#include "ams_mgr_scheduler.h"
|
||||
#include "app_mgr_constants.h"
|
||||
#include "app_mgr_service_event_handler.h"
|
||||
#include "app_mgr_service_inner.h"
|
||||
#include "message_parcel.h"
|
||||
#include "securec.h"
|
||||
|
||||
using namespace OHOS::AAFwk;
|
||||
using namespace OHOS::AppExecFwk;
|
||||
|
||||
namespace OHOS {
|
||||
namespace {
|
||||
constexpr size_t FOO_MAX_LEN = 1024;
|
||||
constexpr size_t U32_AT_SIZE = 4;
|
||||
}
|
||||
const std::u16string AMSMGR_INTERFACE_TOKEN = u"ohos.aafwk.AmsManager";
|
||||
|
||||
uint32_t GetU32Data(const char* ptr)
|
||||
{
|
||||
// convert fuzz input data to an integer
|
||||
return (ptr[0] << 24) | (ptr[1] << 16) | (ptr[2] << 8) | ptr[3];
|
||||
}
|
||||
|
||||
bool DoSomethingInterestingWithMyAPI(const char* data, size_t size)
|
||||
{
|
||||
uint32_t code = GetU32Data(data);
|
||||
|
||||
MessageParcel parcel;
|
||||
parcel.WriteInterfaceToken(AMSMGR_INTERFACE_TOKEN);
|
||||
parcel.WriteBuffer(data, size);
|
||||
parcel.RewindRead(0);
|
||||
MessageParcel reply;
|
||||
MessageOption option;
|
||||
std::shared_ptr<AppMgrServiceInner> appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
|
||||
std::shared_ptr<EventRunner> runner = EventRunner::Create(Constants::APP_MGR_SERVICE_NAME);
|
||||
std::shared_ptr<AMSEventHandler> eventHandler = std::make_shared<AMSEventHandler>(runner, appMgrServiceInner);
|
||||
std::shared_ptr<AmsMgrScheduler> amsMgr = std::make_shared<AmsMgrScheduler>(appMgrServiceInner, eventHandler);
|
||||
amsMgr->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, 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) 2023 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_AMSMANAGER_FUZZER_H
|
||||
#define FUZZTEST_OHOS_ABILITY_RUNTIME_AMSMANAGER_FUZZER_H
|
||||
|
||||
#define FUZZ_PROJECT_NAME "amsmanager_fuzzer"
|
||||
|
||||
#endif // FUZZTEST_OHOS_ABILITY_RUNTIME_AMSMANAGER_FUZZER_H
|
||||
@@ -0,0 +1,16 @@
|
||||
/*
|
||||
* Copyright (c) 2023 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) 2023 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