mirror of
https://gitee.com/openharmony/ability_ability_runtime
synced 2024-11-23 07:10:19 +00:00
commit
94342035ec
@ -28,15 +28,31 @@ group("fuzztest") {
|
||||
"abilityautostartupservicea_fuzzer:fuzztest",
|
||||
"abilityautostartupserviceb_fuzzer:fuzztest",
|
||||
"abilitybackgroundconnection_fuzzer:fuzztest",
|
||||
"abilitybackgroundconnection_fuzzer:fuzztest",
|
||||
"abilitycachemanagera_fuzzer:fuzztest",
|
||||
"abilitychildprocessinfo_fuzzer:fuzztest",
|
||||
"abilitychildprocessrecord_fuzzer:fuzztest",
|
||||
"abilityconnectionstub_fuzzer:fuzztest",
|
||||
"abilityconnectionstub_fuzzer:fuzztest",
|
||||
"abilitycontext_fuzzer:fuzztest",
|
||||
"abilitycontext_fuzzer:fuzztest",
|
||||
"abilitydebugdeal_fuzzer:fuzztest",
|
||||
"abilitydebugdeal_fuzzer:fuzztest",
|
||||
"abilitydebugresponseproxy_fuzzer:fuzztest",
|
||||
"abilityeventutil_fuzzer:fuzztest",
|
||||
"abilityeventutil_fuzzer:fuzztest",
|
||||
"abilityfirstframestateobservermanager_fuzzer:fuzztest",
|
||||
"abilityfirstframestateobservermanager_fuzzer:fuzztest",
|
||||
"abilityforegroundstateobserverproxy_fuzzer:fuzztest",
|
||||
"abilityframeworksnativejsworker_fuzzer:fuzztest",
|
||||
"abilityframeworksnativejsworker_fuzzer:fuzztest",
|
||||
"abilityframeworksnativeohosjsenvlogger_fuzzer:fuzztest",
|
||||
"abilityframeworksnativeohosjsenvlogger_fuzzer:fuzztest",
|
||||
"abilityinterfacesappmanageramsmgrstub_fuzzer:fuzztest",
|
||||
"abilityinterfacesappmgrabilitydebugresponseproxy_fuzzer:fuzztest",
|
||||
"abilityinterfacesappmgrappdebuglistenerproxy_fuzzer:fuzztest",
|
||||
"abilityinterfacesappmgrchildschedulerproxy_fuzzer:fuzztest",
|
||||
"abilityinterfacesappmgrnativechildnotifyproxy_fuzzer:fuzztest",
|
||||
"abilitymanagereventsubscriber_fuzzer:fuzztest",
|
||||
"abilitymanagerserviceb_fuzzer:fuzztest",
|
||||
"abilitymanagerservicec_fuzzer:fuzztest",
|
||||
@ -51,6 +67,7 @@ group("fuzztest") {
|
||||
"abilitymanagerservicesecond_fuzzer:fuzztest",
|
||||
"abilitymanagerservicesixth_fuzzer:fuzztest",
|
||||
"abilitymanagerservicethird_fuzzer:fuzztest",
|
||||
"abilitymgrabilitymanagerstub_fuzzer:fuzztest",
|
||||
"abilitymgrcontrolinterceptor_fuzzer:fuzztest",
|
||||
"abilitymgrdisposedruleinterceptor_fuzzer:fuzztest",
|
||||
"abilitymgrecologicalruleinterceptor_fuzzer:fuzztest",
|
||||
@ -64,6 +81,7 @@ group("fuzztest") {
|
||||
"abilitymgrrdbparserutil_fuzzer:fuzztest",
|
||||
"abilitymgrrest_fuzzer:fuzztest",
|
||||
"abilitymgrrestartappmanager_fuzzer:fuzztest",
|
||||
"abilitymgruiextensionrecord_fuzzer:fuzztest",
|
||||
"abilitymgruiextensionsessioninfo_fuzzer:fuzztest",
|
||||
"abilityrunningrecord_fuzzer:fuzztest",
|
||||
"abilitystubabilityrecovery_fuzzer:fuzztest",
|
||||
@ -198,10 +216,13 @@ group("fuzztest") {
|
||||
"addabilitystagedone_fuzzer:fuzztest",
|
||||
"amsmanager_fuzzer:fuzztest",
|
||||
"amsmgrscheduler_fuzzer:fuzztest",
|
||||
"appforegroundstateobserverproxy_fuzzer:fuzztest",
|
||||
"applifecycledeal_fuzzer:fuzztest",
|
||||
"appmanager_fuzzer:fuzztest",
|
||||
"appmgrclientrest_fuzzer:fuzztest",
|
||||
"appmgrrest_fuzzer:fuzztest",
|
||||
"appmgrstub_fuzzer:fuzztest",
|
||||
"apprunningstatusproxy_fuzzer:fuzztest",
|
||||
"appstateobservermanager_fuzzer:fuzztest",
|
||||
"assertfaultcallbackdeathmgr_fuzzer:fuzztest",
|
||||
"attachabilitythread_fuzzer:fuzztest",
|
||||
@ -280,6 +301,7 @@ group("fuzztest") {
|
||||
"registermissionlistener_fuzzer:fuzztest",
|
||||
"releasedataability_fuzzer:fuzztest",
|
||||
"remotemissionlistenerstub_fuzzer:fuzztest",
|
||||
"renderstateobserverproxy_fuzzer:fuzztest",
|
||||
"scheduleacceptwantdone_fuzzer:fuzztest",
|
||||
"schedulecommandabilitydone_fuzzer:fuzztest",
|
||||
"scheduleconnectabilitydone_fuzzer:fuzztest",
|
||||
|
63
test/fuzztest/abilityappdebuginfo_fuzzer/BUILD.gn
Normal file
63
test/fuzztest/abilityappdebuginfo_fuzzer/BUILD.gn
Normal file
@ -0,0 +1,63 @@
|
||||
# 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/test.gni")
|
||||
import("//foundation/ability/ability_runtime/ability_runtime.gni")
|
||||
##############################fuzztest##########################################
|
||||
module_output_path = "ability_runtime/appmgrservice"
|
||||
ohos_fuzztest("AbilityAppDebugInfoFuzzTest") {
|
||||
module_out_path = module_output_path
|
||||
fuzz_config_file =
|
||||
"${ability_runtime_test_path}/fuzztest/abilityappdebuginfo_fuzzer"
|
||||
include_dirs = [ "${ability_runtime_services_path}/appmgr/include" ]
|
||||
|
||||
cflags = [
|
||||
"-g",
|
||||
"-O0",
|
||||
"-Wno-unused-variable",
|
||||
"-fno-omit-frame-pointer",
|
||||
]
|
||||
sources = [ "abilityappdebuginfo_fuzzer.cpp" ]
|
||||
|
||||
deps = [
|
||||
"${ability_runtime_innerkits_path}/app_manager:app_manager",
|
||||
"${ability_runtime_services_path}/appmgr:libappms",
|
||||
"${ability_runtime_services_path}/common:task_handler_wrap",
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
"ability_base:want",
|
||||
"appspawn:appspawn_client",
|
||||
"bundle_framework:appexecfwk_base",
|
||||
"bundle_framework:appexecfwk_core",
|
||||
"c_utils:utils",
|
||||
"ffrt:libffrt",
|
||||
"hilog:libhilog",
|
||||
"init:libbegetutil",
|
||||
"ipc:ipc_core",
|
||||
"samgr:samgr_proxy",
|
||||
"window_manager:libwm",
|
||||
]
|
||||
}
|
||||
|
||||
###############################################################################
|
||||
group("fuzztest") {
|
||||
testonly = true
|
||||
deps = []
|
||||
deps += [
|
||||
# deps file
|
||||
":AbilityAppDebugInfoFuzzTest",
|
||||
]
|
||||
}
|
||||
###############################################################################
|
@ -0,0 +1,101 @@
|
||||
/*
|
||||
* Copyright (c) 2022 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 "abilityappdebuginfo_fuzzer.h"
|
||||
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
|
||||
#define private public
|
||||
#define protected public
|
||||
#include "app_debug_info.h"
|
||||
#undef protected
|
||||
#undef private
|
||||
#include "parcel.h"
|
||||
#include <iostream>
|
||||
#include "securec.h"
|
||||
#include "configuration.h"
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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];
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool DoSomethingInterestingWithMyAPI(const char* data, size_t size)
|
||||
{
|
||||
std::shared_ptr<AppDebugInfo>appDebugInfo = std::make_shared<AppDebugInfo>();
|
||||
if (appDebugInfo == nullptr) {
|
||||
return false;
|
||||
}
|
||||
Parcel parcel;
|
||||
appDebugInfo->ReadFromParcel(parcel);
|
||||
appDebugInfo->Marshalling(parcel);
|
||||
AppDebugInfo::Unmarshalling(parcel);
|
||||
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, 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) 2022 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_ABILITYAPPDEBUGINFO_FUZZER_H
|
||||
#define FUZZTEST_OHOS_ABILITY_RUNTIME_ABILITYAPPDEBUGINFO_FUZZER_H
|
||||
|
||||
#define FUZZ_PROJECT_NAME "abilityappdebuginfo_fuzzer"
|
||||
|
||||
#endif // FUZZTEST_OHOS_ABILITY_RUNTIME_ABILITYMANAGERSERVICEA_FUZZER_H
|
16
test/fuzztest/abilityappdebuginfo_fuzzer/corpus/init
Normal file
16
test/fuzztest/abilityappdebuginfo_fuzzer/corpus/init
Normal file
@ -0,0 +1,16 @@
|
||||
/*
|
||||
* Copyright (c) 2022 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
|
25
test/fuzztest/abilityappdebuginfo_fuzzer/project.xml
Normal file
25
test/fuzztest/abilityappdebuginfo_fuzzer/project.xml
Normal file
@ -0,0 +1,25 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Copyright (c) 2022 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>
|
66
test/fuzztest/abilityappdebugmanager_fuzzer/BUILD.gn
Normal file
66
test/fuzztest/abilityappdebugmanager_fuzzer/BUILD.gn
Normal file
@ -0,0 +1,66 @@
|
||||
# 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/test.gni")
|
||||
import("//foundation/ability/ability_runtime/ability_runtime.gni")
|
||||
##############################fuzztest##########################################
|
||||
module_output_path = "ability_runtime/appmgrservice"
|
||||
ohos_fuzztest("AbilityAppDebugManagerFuzzTest") {
|
||||
module_out_path = module_output_path
|
||||
|
||||
fuzz_config_file =
|
||||
"${ability_runtime_test_path}/fuzztest/abilityappdebugmanager_fuzzer"
|
||||
|
||||
include_dirs = [ "${ability_runtime_services_path}/appmgr/include" ]
|
||||
|
||||
cflags = [
|
||||
"-g",
|
||||
"-O0",
|
||||
"-Wno-unused-variable",
|
||||
"-fno-omit-frame-pointer",
|
||||
]
|
||||
sources = [
|
||||
"${ability_runtime_services_path}/appmgr/src/app_debug_manager.cpp",
|
||||
"abilityappdebugmanager_fuzzer.cpp",
|
||||
]
|
||||
|
||||
configs = [ "${ability_runtime_innerkits_path}/ability_manager:ability_manager_public_config" ]
|
||||
|
||||
deps = [
|
||||
"${ability_runtime_innerkits_path}/app_manager:app_manager",
|
||||
"${ability_runtime_services_path}/appmgr:libappms",
|
||||
"${ability_runtime_services_path}/common:task_handler_wrap",
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
"appspawn:appspawn_client",
|
||||
"bundle_framework:appexecfwk_base",
|
||||
"bundle_framework:appexecfwk_core",
|
||||
"c_utils:utils",
|
||||
"hilog:libhilog",
|
||||
"init:libbegetutil",
|
||||
"ipc:ipc_core",
|
||||
]
|
||||
}
|
||||
|
||||
###############################################################################
|
||||
group("fuzztest") {
|
||||
testonly = true
|
||||
deps = []
|
||||
deps += [
|
||||
# deps file
|
||||
":AbilityAppDebugManagerFuzzTest",
|
||||
]
|
||||
}
|
||||
###############################################################################
|
@ -0,0 +1,89 @@
|
||||
/*
|
||||
* Copyright (c) 2022 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 "abilityappdebugmanager_fuzzer.h"
|
||||
|
||||
#define private public
|
||||
#include "app_debug_manager.h"
|
||||
#include "app_debug_listener_proxy.h"
|
||||
#undef private
|
||||
|
||||
#include <iostream>
|
||||
#include "securec.h"
|
||||
#include "configuration.h"
|
||||
|
||||
using namespace OHOS::AppExecFwk;
|
||||
|
||||
namespace OHOS {
|
||||
namespace {
|
||||
constexpr size_t FOO_MAX_LEN = 1024;
|
||||
constexpr size_t U32_AT_SIZE = 4;
|
||||
}
|
||||
|
||||
bool DoSomethingInterestingWithMyAPI(const char* data, size_t size)
|
||||
{
|
||||
std::shared_ptr<AppDebugManager> manager=std::make_shared<AppDebugManager>();
|
||||
if (!manager) {
|
||||
return false;
|
||||
}
|
||||
sptr<IAppDebugListener> listener;
|
||||
manager->RegisterAppDebugListener(listener);
|
||||
manager->UnregisterAppDebugListener(listener);
|
||||
std::vector<AppDebugInfo> infos;
|
||||
manager->StartDebug(infos);
|
||||
manager->StopDebug(infos);
|
||||
std::string stringParam(data, size);
|
||||
manager->IsAttachDebug(stringParam);
|
||||
AppDebugInfo info;
|
||||
manager->RemoveAppDebugInfo(info);
|
||||
std::vector<AppDebugInfo> incrementInfos;
|
||||
manager->GetIncrementAppDebugInfos(infos,incrementInfos);
|
||||
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) 2022 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_ABILITYAPPDEBUGMANAGER_FUZZER_H
|
||||
#define FUZZTEST_OHOS_ABILITY_RUNTIME_ABILITYAPPDEBUGMANAGER_FUZZER_H
|
||||
|
||||
#define FUZZ_PROJECT_NAME "abilityappdebugmanager_fuzzer"
|
||||
|
||||
#endif // FUZZTEST_OHOS_ABILITY_RUNTIME_ABILITYATTACHTIMEOUT_FUZZER_H
|
16
test/fuzztest/abilityappdebugmanager_fuzzer/corpus/init
Normal file
16
test/fuzztest/abilityappdebugmanager_fuzzer/corpus/init
Normal file
@ -0,0 +1,16 @@
|
||||
/*
|
||||
* Copyright (c) 2022 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
|
25
test/fuzztest/abilityappdebugmanager_fuzzer/project.xml
Normal file
25
test/fuzztest/abilityappdebugmanager_fuzzer/project.xml
Normal file
@ -0,0 +1,25 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Copyright (c) 2022 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>
|
66
test/fuzztest/abilityappjsheapmeminfo_fuzzer/BUILD.gn
Normal file
66
test/fuzztest/abilityappjsheapmeminfo_fuzzer/BUILD.gn
Normal file
@ -0,0 +1,66 @@
|
||||
# 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/test.gni")
|
||||
import("//foundation/ability/ability_runtime/ability_runtime.gni")
|
||||
##############################fuzztest##########################################
|
||||
module_output_path = "ability_runtime/appmgrservice"
|
||||
ohos_fuzztest("AbilityAppJsHeapMemInfoFuzzTest") {
|
||||
module_out_path = module_output_path
|
||||
fuzz_config_file =
|
||||
"${ability_runtime_test_path}/fuzztest/abilityappjsheapmeminfo_fuzzer"
|
||||
include_dirs = [ "${ability_runtime_services_path}/appmgr/include" ]
|
||||
|
||||
cflags = [
|
||||
"-g",
|
||||
"-O0",
|
||||
"-Wno-unused-variable",
|
||||
"-fno-omit-frame-pointer",
|
||||
]
|
||||
sources = [
|
||||
"${ability_runtime_innerkits_path}/app_manager/src/appmgr/app_jsheap_mem_info.cpp",
|
||||
"abilityappjsheapmeminfo_fuzzer.cpp",
|
||||
]
|
||||
|
||||
deps = [
|
||||
"${ability_runtime_innerkits_path}/app_manager:app_manager",
|
||||
"${ability_runtime_services_path}/appmgr:libappms",
|
||||
"${ability_runtime_services_path}/common:task_handler_wrap",
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
"ability_base:want",
|
||||
"appspawn:appspawn_client",
|
||||
"bundle_framework:appexecfwk_base",
|
||||
"bundle_framework:appexecfwk_core",
|
||||
"c_utils:utils",
|
||||
"ffrt:libffrt",
|
||||
"hilog:libhilog",
|
||||
"init:libbegetutil",
|
||||
"ipc:ipc_core",
|
||||
"samgr:samgr_proxy",
|
||||
"window_manager:libwm",
|
||||
]
|
||||
}
|
||||
|
||||
###############################################################################
|
||||
group("fuzztest") {
|
||||
testonly = true
|
||||
deps = []
|
||||
deps += [
|
||||
# deps file
|
||||
":AbilityAppJsHeapMemInfoFuzzTest",
|
||||
]
|
||||
}
|
||||
###############################################################################
|
@ -0,0 +1,96 @@
|
||||
/*
|
||||
* Copyright (c) 2022 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 "abilityappjsheapmeminfo_fuzzer.h"
|
||||
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
|
||||
#define private public
|
||||
#define protected public
|
||||
#include "app_jsheap_mem_info.h"
|
||||
#undef protected
|
||||
#undef private
|
||||
#include "parcel.h"
|
||||
#include <iostream>
|
||||
#include "securec.h"
|
||||
#include "configuration.h"
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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];
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool DoSomethingInterestingWithMyAPI(const char* data, size_t size)
|
||||
{
|
||||
JsHeapDumpInfo js;
|
||||
Parcel parcel;
|
||||
js.Marshalling(parcel);
|
||||
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, 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) 2022 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_ABILITYAPPJSHEAPMEMINFO_FUZZER_H
|
||||
#define FUZZTEST_OHOS_ABILITY_RUNTIME_ABILITYAPPJSHEAPMEMINFO_FUZZER_H
|
||||
|
||||
#define FUZZ_PROJECT_NAME "abilityappjsheapmeminfo_fuzzer"
|
||||
|
||||
#endif // FUZZTEST_OHOS_ABILITY_RUNTIME_ABILITYMANAGERSERVICEA_FUZZER_H
|
16
test/fuzztest/abilityappjsheapmeminfo_fuzzer/corpus/init
Normal file
16
test/fuzztest/abilityappjsheapmeminfo_fuzzer/corpus/init
Normal file
@ -0,0 +1,16 @@
|
||||
/*
|
||||
* Copyright (c) 2022 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
|
25
test/fuzztest/abilityappjsheapmeminfo_fuzzer/project.xml
Normal file
25
test/fuzztest/abilityappjsheapmeminfo_fuzzer/project.xml
Normal file
@ -0,0 +1,25 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Copyright (c) 2022 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>
|
83
test/fuzztest/abilityappmgrevent_fuzzer/BUILD.gn
Normal file
83
test/fuzztest/abilityappmgrevent_fuzzer/BUILD.gn
Normal file
@ -0,0 +1,83 @@
|
||||
# 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/test.gni")
|
||||
import("//foundation/ability/ability_runtime/ability_runtime.gni")
|
||||
##############################fuzztest##########################################
|
||||
module_output_path = "ability_runtime/appmgrservice"
|
||||
ohos_fuzztest("AbilityAppMgrEventFuzzTest") {
|
||||
module_out_path = module_output_path
|
||||
|
||||
fuzz_config_file =
|
||||
"${ability_runtime_test_path}/fuzztest/abilityappmgrevent_fuzzer"
|
||||
|
||||
include_dirs =
|
||||
[ "${ability_runtime_innerkits_path}/app_manager/include/appmgr" ]
|
||||
|
||||
cflags = [
|
||||
"-g",
|
||||
"-O0",
|
||||
"-Wno-unused-variable",
|
||||
"-fno-omit-frame-pointer",
|
||||
]
|
||||
sources = [
|
||||
"${ability_runtime_services_path}/appmgr/src/app_mgr_event.cpp",
|
||||
"${ability_runtime_services_path}/common/src/event_report.cpp",
|
||||
"abilityappmgrevent_fuzzer.cpp",
|
||||
]
|
||||
|
||||
configs = [ "${ability_runtime_services_path}/appmgr:appmgr_config" ]
|
||||
|
||||
deps = [ "${ability_runtime_services_path}/appmgr:libappms" ]
|
||||
|
||||
external_deps = [
|
||||
"ability_base:configuration",
|
||||
"ability_base:want",
|
||||
"ability_runtime:app_manager",
|
||||
"access_token:libaccesstoken_sdk",
|
||||
"access_token:libnativetoken",
|
||||
"access_token:libtoken_setproc",
|
||||
"appspawn:appspawn_client",
|
||||
"bundle_framework:appexecfwk_base",
|
||||
"bundle_framework:appexecfwk_core",
|
||||
"c_utils:utils",
|
||||
"ffrt:libffrt",
|
||||
"hilog:libhilog",
|
||||
"hisysevent:libhisysevent",
|
||||
"hitrace:hitrace_meter",
|
||||
"init:libbeget_proxy",
|
||||
"init:libbegetutil",
|
||||
"ipc:ipc_core",
|
||||
]
|
||||
|
||||
if (ability_runtime_graphics) {
|
||||
external_deps += [ "window_manager:libwm" ]
|
||||
}
|
||||
|
||||
defines = []
|
||||
if (background_task_mgr_continuous_task_enable) {
|
||||
defines += [ "BGTASKMGR_CONTINUOUS_TASK_ENABLE" ]
|
||||
}
|
||||
}
|
||||
|
||||
###############################################################################
|
||||
group("fuzztest") {
|
||||
testonly = true
|
||||
deps = []
|
||||
deps += [
|
||||
# deps file
|
||||
":AbilityAppMgrEventFuzzTest",
|
||||
]
|
||||
}
|
||||
###############################################################################
|
@ -0,0 +1,94 @@
|
||||
/*
|
||||
* Copyright (c) 2022 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 "abilityappmgrevent_fuzzer.h"
|
||||
|
||||
#define private public
|
||||
#include "app_mgr_event.h"
|
||||
#undef private
|
||||
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <iostream>
|
||||
#include "securec.h"
|
||||
#include "configuration.h"
|
||||
using namespace OHOS::AppExecFwk;
|
||||
|
||||
namespace OHOS {
|
||||
namespace {
|
||||
constexpr size_t FOO_MAX_LEN = 1024;
|
||||
constexpr size_t U32_AT_SIZE = 4;
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
std::shared_ptr<AppRunningRecord> callerAppRecord;
|
||||
std::shared_ptr<AppRunningRecord> appRecord;
|
||||
std::string stringParam(data, size);
|
||||
AppMgrEventUtil::SendCreateAtomicServiceProcessEvent(callerAppRecord, appRecord,
|
||||
stringParam, stringParam);
|
||||
AAFwk::EventInfo eventInfo;
|
||||
AppMgrEventUtil::SendProcessStartEvent(callerAppRecord,appRecord,eventInfo);
|
||||
int32_t appUid = static_cast<int32_t>(GetU32Data(data));
|
||||
int64_t restartTime = static_cast<int64_t>(GetU32Data(data));
|
||||
AppMgrEventUtil::SendReStartProcessEvent(eventInfo, appUid, restartTime);
|
||||
AppMgrEventUtil:: GetCallerPid(callerAppRecord);
|
||||
std::shared_ptr<AbilityInfo> abilityInfo;
|
||||
int32_t abilityType = static_cast<int32_t>(GetU32Data(data));
|
||||
int32_t extensionType = static_cast<int32_t>(GetU32Data(data));
|
||||
AppMgrEventUtil:: UpdateStartupType(abilityInfo, abilityType,extensionType);
|
||||
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) 2022 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_ABILITYAPPMGREVENT_FUZZER_H
|
||||
#define FUZZTEST_OHOS_ABILITY_RUNTIME_ABILITYAPPMGREVENT_FUZZER_H
|
||||
|
||||
#define FUZZ_PROJECT_NAME "abilityappmgrevent_fuzzer"
|
||||
|
||||
#endif // FUZZTEST_OHOS_ABILITY_RUNTIME_ABILITYATTACHTIMEOUT_FUZZER_H
|
16
test/fuzztest/abilityappmgrevent_fuzzer/corpus/init
Normal file
16
test/fuzztest/abilityappmgrevent_fuzzer/corpus/init
Normal file
@ -0,0 +1,16 @@
|
||||
/*
|
||||
* Copyright (c) 2022 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
|
25
test/fuzztest/abilityappmgrevent_fuzzer/project.xml
Normal file
25
test/fuzztest/abilityappmgrevent_fuzzer/project.xml
Normal file
@ -0,0 +1,25 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Copyright (c) 2022 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>
|
63
test/fuzztest/abilitychildprocessinfo_fuzzer/BUILD.gn
Normal file
63
test/fuzztest/abilitychildprocessinfo_fuzzer/BUILD.gn
Normal file
@ -0,0 +1,63 @@
|
||||
# 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/test.gni")
|
||||
import("//foundation/ability/ability_runtime/ability_runtime.gni")
|
||||
##############################fuzztest##########################################
|
||||
module_output_path = "ability_runtime/appmgrservice"
|
||||
ohos_fuzztest("AbilityChildProcessInfoFuzzTest") {
|
||||
module_out_path = module_output_path
|
||||
fuzz_config_file =
|
||||
"${ability_runtime_test_path}/fuzztest/abilitychildprocessinfo_fuzzer"
|
||||
include_dirs = [ "${ability_runtime_services_path}/appmgr/include" ]
|
||||
|
||||
cflags = [
|
||||
"-g",
|
||||
"-O0",
|
||||
"-Wno-unused-variable",
|
||||
"-fno-omit-frame-pointer",
|
||||
]
|
||||
sources = [ "abilitychildprocessinfo_fuzzer.cpp" ]
|
||||
|
||||
deps = [
|
||||
"${ability_runtime_innerkits_path}/app_manager:app_manager",
|
||||
"${ability_runtime_services_path}/appmgr:libappms",
|
||||
"${ability_runtime_services_path}/common:task_handler_wrap",
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
"ability_base:want",
|
||||
"appspawn:appspawn_client",
|
||||
"bundle_framework:appexecfwk_base",
|
||||
"bundle_framework:appexecfwk_core",
|
||||
"c_utils:utils",
|
||||
"ffrt:libffrt",
|
||||
"hilog:libhilog",
|
||||
"init:libbegetutil",
|
||||
"ipc:ipc_core",
|
||||
"samgr:samgr_proxy",
|
||||
"window_manager:libwm",
|
||||
]
|
||||
}
|
||||
|
||||
###############################################################################
|
||||
group("fuzztest") {
|
||||
testonly = true
|
||||
deps = []
|
||||
deps += [
|
||||
# deps file
|
||||
":AbilityChildProcessInfoFuzzTest",
|
||||
]
|
||||
}
|
||||
###############################################################################
|
@ -0,0 +1,99 @@
|
||||
/*
|
||||
* Copyright (c) 2022 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 "abilitychildprocessinfo_fuzzer.h"
|
||||
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
|
||||
#define private public
|
||||
#define protected public
|
||||
#include "child_process_info.h"
|
||||
#undef protected
|
||||
#undef private
|
||||
#include "parcel.h"
|
||||
#include <iostream>
|
||||
#include "securec.h"
|
||||
#include "configuration.h"
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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];
|
||||
}
|
||||
|
||||
bool DoSomethingInterestingWithMyAPI(const char* data, size_t size)
|
||||
{
|
||||
std::shared_ptr<ChildProcessInfo>childProcessInfo = std::make_shared<ChildProcessInfo>();
|
||||
if (childProcessInfo == nullptr) {
|
||||
return false;
|
||||
}
|
||||
Parcel parcel;
|
||||
childProcessInfo->ReadFromParcel(parcel);
|
||||
childProcessInfo->Marshalling(parcel);
|
||||
ChildProcessInfo::Unmarshalling(parcel);
|
||||
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, 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) 2022 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_ABILITYCHILDPROCESSINFO_FUZZER_H
|
||||
#define FUZZTEST_OHOS_ABILITY_RUNTIME_ABILITYCHILDPROCESSINFO_FUZZER_H
|
||||
|
||||
#define FUZZ_PROJECT_NAME "abilitychildprocessinfo_fuzzer"
|
||||
|
||||
#endif // FUZZTEST_OHOS_ABILITY_RUNTIME_ABILITYMANAGERSERVICEA_FUZZER_H
|
16
test/fuzztest/abilitychildprocessinfo_fuzzer/corpus/init
Normal file
16
test/fuzztest/abilitychildprocessinfo_fuzzer/corpus/init
Normal file
@ -0,0 +1,16 @@
|
||||
/*
|
||||
* Copyright (c) 2022 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
|
25
test/fuzztest/abilitychildprocessinfo_fuzzer/project.xml
Normal file
25
test/fuzztest/abilitychildprocessinfo_fuzzer/project.xml
Normal file
@ -0,0 +1,25 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Copyright (c) 2022 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>
|
98
test/fuzztest/abilitychildprocessrecord_fuzzer/BUILD.gn
Normal file
98
test/fuzztest/abilitychildprocessrecord_fuzzer/BUILD.gn
Normal file
@ -0,0 +1,98 @@
|
||||
# Copyright (c) 2022 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/test.gni")
|
||||
import("//foundation/ability/ability_runtime/ability_runtime.gni")
|
||||
##############################fuzztest##########################################
|
||||
module_output_path = "ability_runtime/appmgrservice"
|
||||
ohos_fuzztest("AbilityChildProcessRecordFuzzTest") {
|
||||
module_out_path = module_output_path
|
||||
|
||||
fuzz_config_file =
|
||||
"${ability_runtime_test_path}/fuzztest/abilitychildprocessrecord_fuzzer"
|
||||
|
||||
include_dirs = [
|
||||
"${ability_runtime_innerkits_path}/ability_manager/include/",
|
||||
"${ability_runtime_services_path}/appmgr/include/",
|
||||
"{ability_runtime_services_path}/include/",
|
||||
"${ability_runtime_innerkits_path}/app_manager/include/appmgr/",
|
||||
]
|
||||
|
||||
cflags = [
|
||||
"-g",
|
||||
"-O0",
|
||||
"-Wno-unused-variable",
|
||||
"-fno-omit-frame-pointer",
|
||||
]
|
||||
sources = [
|
||||
"${ability_runtime_innerkits_path}/app_manager/src/appmgr/child_process_args.cpp",
|
||||
"${ability_runtime_innerkits_path}/app_manager/src/appmgr/child_process_options.cpp",
|
||||
"${ability_runtime_innerkits_path}/app_manager/src/appmgr/child_process_request.cpp",
|
||||
"${ability_runtime_services_path}/appmgr/src/child_process_record.cpp",
|
||||
"abilitychildprocessrecord_fuzzer.cpp",
|
||||
]
|
||||
|
||||
configs = [ "${ability_runtime_services_path}/appmgr:appmgr_config" ]
|
||||
|
||||
deps = [
|
||||
"${ability_runtime_innerkits_path}/app_manager:app_manager",
|
||||
"${ability_runtime_innerkits_path}/deps_wrapper:ability_deps_wrapper",
|
||||
"${ability_runtime_innerkits_path}/uri_permission:uri_permission_mgr",
|
||||
"${ability_runtime_services_path}/appmgr:libappms",
|
||||
"${ability_runtime_services_path}/common:event_report",
|
||||
"${ability_runtime_services_path}/common:perm_verification",
|
||||
"${ability_runtime_services_path}/common:task_handler_wrap",
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
"ability_base:base",
|
||||
"ability_base:configuration",
|
||||
"ability_base:want",
|
||||
"access_token:libaccesstoken_sdk",
|
||||
"appspawn:appspawn_client",
|
||||
"bundle_framework:appexecfwk_base",
|
||||
"bundle_framework:appexecfwk_core",
|
||||
"c_utils:utils",
|
||||
"common_event_service:cesfwk_innerkits",
|
||||
"ffrt:libffrt",
|
||||
"hicollie:libhicollie",
|
||||
"hilog:libhilog",
|
||||
"hisysevent:libhisysevent",
|
||||
"hitrace:hitrace_meter",
|
||||
"init:libbeget_proxy",
|
||||
"init:libbegetutil",
|
||||
"ipc:ipc_core",
|
||||
"kv_store:distributeddata_mgr",
|
||||
"memory_utils:libmeminfo",
|
||||
"safwk:system_ability_fwk",
|
||||
"samgr:samgr_proxy",
|
||||
"window_manager:libwm",
|
||||
"window_manager:libwsutils",
|
||||
]
|
||||
|
||||
if (ability_runtime_graphics) {
|
||||
external_deps += [ "window_manager:libwm" ]
|
||||
}
|
||||
}
|
||||
|
||||
###############################################################################
|
||||
group("fuzztest") {
|
||||
testonly = true
|
||||
deps = []
|
||||
deps += [
|
||||
# deps file
|
||||
":AbilityChildProcessRecordFuzzTest",
|
||||
]
|
||||
}
|
||||
###############################################################################
|
@ -0,0 +1,119 @@
|
||||
/*
|
||||
* Copyright (c) 2022 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 "abilitychildprocessrecord_fuzzer.h"
|
||||
|
||||
#define private public
|
||||
#include "app_running_record.h"
|
||||
#include "child_process_record.h"
|
||||
#undef private
|
||||
#include "child_process_request.h"
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <iostream>
|
||||
#include "securec.h"
|
||||
#include "configuration.h"
|
||||
using namespace OHOS::AppExecFwk;
|
||||
using namespace OHOS::AAFwk;
|
||||
namespace OHOS {
|
||||
namespace {
|
||||
constexpr size_t FOO_MAX_LEN = 1024;
|
||||
constexpr size_t U32_AT_SIZE = 4;
|
||||
constexpr uint8_t ENABLE = 2;
|
||||
}
|
||||
|
||||
|
||||
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)
|
||||
{
|
||||
int32_t hostPid = static_cast<int32_t>(GetU32Data(data));
|
||||
ChildProcessRequest request;
|
||||
std::shared_ptr<AppRunningRecord> hostRecord;
|
||||
ChildProcessRecord::CreateChildProcessRecord(hostPid,request,hostRecord);
|
||||
std::string stringParam(data, size);
|
||||
sptr<IRemoteObject> mainProcessCb;
|
||||
int32_t childProcessCount =static_cast<int32_t>(GetU32Data(data));
|
||||
bool isStartWithDebug = *data % ENABLE;
|
||||
ChildProcessRecord::CreateNativeChildProcessRecord(hostPid,stringParam,hostRecord,mainProcessCb,childProcessCount,isStartWithDebug);
|
||||
std::shared_ptr<ApplicationInfo> appInfo = std::make_shared<ApplicationInfo>();
|
||||
int32_t RECORD_ID = static_cast<int32_t>(GetU32Data(data));
|
||||
auto appRecord = std::make_shared<AppRunningRecord>(appInfo, RECORD_ID, stringParam);
|
||||
auto childRecord = std::make_shared<ChildProcessRecord>(hostPid, request, appRecord);
|
||||
childRecord->SetPid(hostPid);
|
||||
childRecord->GetPid();
|
||||
childRecord->GetHostPid();
|
||||
int32_t uid = static_cast<int32_t>(GetU32Data(data));
|
||||
childRecord->SetUid(uid);
|
||||
childRecord->GetUid();
|
||||
childRecord->GetProcessName();
|
||||
childRecord->GetSrcEntry();
|
||||
childRecord->GetHostRecord();
|
||||
sptr<IChildScheduler> scheduler;
|
||||
childRecord->SetScheduler(scheduler);
|
||||
sptr<AppDeathRecipient> recipient;
|
||||
childRecord->SetDeathRecipient(recipient);
|
||||
childRecord->RegisterDeathRecipient();
|
||||
childRecord-> RemoveDeathRecipient();
|
||||
childRecord-> ScheduleExitProcessSafely();
|
||||
childRecord->isStartWithDebug();
|
||||
childRecord-> GetChildProcessType();
|
||||
childRecord->GetMainProcessCallback();
|
||||
childRecord->ClearMainProcessCallback();
|
||||
std::string entryParams(data, size);
|
||||
childRecord->GetEntryParams();
|
||||
childRecord->MakeProcessName(hostRecord);
|
||||
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) 2022 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_ABILITYCHILDPROCESSRECORD_FUZZER_H
|
||||
#define FUZZTEST_OHOS_ABILITY_RUNTIME_ABILITYCHILDPROCESSRECORD_FUZZER_H
|
||||
|
||||
#define FUZZ_PROJECT_NAME "abilitychildprocessrecord_fuzzer"
|
||||
|
||||
#endif // FUZZTEST_OHOS_ABILITY_RUNTIME_ABILITYATTACHTIMEOUT_FUZZER_H
|
16
test/fuzztest/abilitychildprocessrecord_fuzzer/corpus/init
Normal file
16
test/fuzztest/abilitychildprocessrecord_fuzzer/corpus/init
Normal file
@ -0,0 +1,16 @@
|
||||
/*
|
||||
* Copyright (c) 2022 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
|
25
test/fuzztest/abilitychildprocessrecord_fuzzer/project.xml
Normal file
25
test/fuzztest/abilitychildprocessrecord_fuzzer/project.xml
Normal file
@ -0,0 +1,25 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Copyright (c) 2022 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>
|
63
test/fuzztest/abilitymemorylevelinfo_fuzzer/BUILD.gn
Normal file
63
test/fuzztest/abilitymemorylevelinfo_fuzzer/BUILD.gn
Normal file
@ -0,0 +1,63 @@
|
||||
# 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/test.gni")
|
||||
import("//foundation/ability/ability_runtime/ability_runtime.gni")
|
||||
##############################fuzztest##########################################
|
||||
module_output_path = "ability_runtime/appmgrservice"
|
||||
ohos_fuzztest("AbilityMemoryLevelInfoFuzzTest") {
|
||||
module_out_path = module_output_path
|
||||
fuzz_config_file =
|
||||
"${ability_runtime_test_path}/fuzztest/abilitymemorylevelinfo_fuzzer"
|
||||
include_dirs = [ "${ability_runtime_services_path}/appmgr/include" ]
|
||||
|
||||
cflags = [
|
||||
"-g",
|
||||
"-O0",
|
||||
"-Wno-unused-variable",
|
||||
"-fno-omit-frame-pointer",
|
||||
]
|
||||
sources = [ "abilitymemorylevelinfo_fuzzer.cpp" ]
|
||||
|
||||
deps = [
|
||||
"${ability_runtime_innerkits_path}/app_manager:app_manager",
|
||||
"${ability_runtime_services_path}/appmgr:libappms",
|
||||
"${ability_runtime_services_path}/common:task_handler_wrap",
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
"ability_base:want",
|
||||
"appspawn:appspawn_client",
|
||||
"bundle_framework:appexecfwk_base",
|
||||
"bundle_framework:appexecfwk_core",
|
||||
"c_utils:utils",
|
||||
"ffrt:libffrt",
|
||||
"hilog:libhilog",
|
||||
"init:libbegetutil",
|
||||
"ipc:ipc_core",
|
||||
"samgr:samgr_proxy",
|
||||
"window_manager:libwm",
|
||||
]
|
||||
}
|
||||
|
||||
###############################################################################
|
||||
group("fuzztest") {
|
||||
testonly = true
|
||||
deps = []
|
||||
deps += [
|
||||
# deps file
|
||||
":AbilityMemoryLevelInfoFuzzTest",
|
||||
]
|
||||
}
|
||||
###############################################################################
|
@ -0,0 +1,101 @@
|
||||
/*
|
||||
* Copyright (c) 2022 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 "abilitymemorylevelinfo_fuzzer.h"
|
||||
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
|
||||
#define private public
|
||||
#define protected public
|
||||
#include "memory_level_info.h"
|
||||
#undef protected
|
||||
#undef private
|
||||
#include "parcel.h"
|
||||
#include <iostream>
|
||||
#include "securec.h"
|
||||
#include "configuration.h"
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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];
|
||||
}
|
||||
|
||||
bool DoSomethingInterestingWithMyAPI(const char* data, size_t size)
|
||||
{
|
||||
|
||||
std::shared_ptr<MemoryLevelInfo>memLevelInfo = std::make_shared<MemoryLevelInfo>();
|
||||
if (memLevelInfo == nullptr) {
|
||||
return false;
|
||||
}
|
||||
Parcel parcel;
|
||||
memLevelInfo->GetProcLevelMap();
|
||||
memLevelInfo->Marshalling(parcel);
|
||||
memLevelInfo->ReadFromParcel(parcel);
|
||||
MemoryLevelInfo::Unmarshalling(parcel);
|
||||
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, 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) 2022 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_ABILITYMEMORYLEVELINFO_FUZZER_H
|
||||
#define FUZZTEST_OHOS_ABILITY_RUNTIME_ABILITYMEMORYLEVELINFO_FUZZER_H
|
||||
|
||||
#define FUZZ_PROJECT_NAME "abilitymemorylevelinfo_fuzzer"
|
||||
|
||||
#endif // FUZZTEST_OHOS_ABILITY_RUNTIME_ABILITYMANAGERSERVICEA_FUZZER_H
|
16
test/fuzztest/abilitymemorylevelinfo_fuzzer/corpus/init
Normal file
16
test/fuzztest/abilitymemorylevelinfo_fuzzer/corpus/init
Normal file
@ -0,0 +1,16 @@
|
||||
/*
|
||||
* Copyright (c) 2022 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
|
25
test/fuzztest/abilitymemorylevelinfo_fuzzer/project.xml
Normal file
25
test/fuzztest/abilitymemorylevelinfo_fuzzer/project.xml
Normal file
@ -0,0 +1,25 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Copyright (c) 2022 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>
|
Loading…
Reference in New Issue
Block a user