!3605 补充FUZZ测试套

Merge pull request !3605 from 周士成/fuzz
This commit is contained in:
openharmony_ci
2022-10-27 06:03:37 +00:00
committed by Gitee
43 changed files with 1966 additions and 9 deletions
+8
View File
@@ -30,10 +30,15 @@ group("fuzztest") {
"cleanmission_fuzzer:fuzztest",
"clearupapplicationdata_fuzzer:fuzztest",
"closeability_fuzzer:fuzztest",
"completefirstframedrawing_fuzzer:fuzztest",
"connectability_fuzzer:fuzztest",
"continueability_fuzzer:fuzztest",
"continuemission_fuzzer:fuzztest",
"delegatordoabilitybackground_fuzzer:fuzztest",
"delegatordoabilityforeground_fuzzer:fuzztest",
"disconnectability_fuzzer:fuzztest",
"doabilitybackground_fuzzer:fuzztest",
"doabilityforeground_fuzzer:fuzztest",
"dumpstate_fuzzer:fuzztest",
"dumpsysstate_fuzzer:fuzztest",
"finishusertest_fuzzer:fuzztest",
@@ -43,6 +48,7 @@ group("fuzztest") {
"getextensionrunninginfos_fuzzer:fuzztest",
"getmissionidbytoken_fuzzer:fuzztest",
"getmissioninfos_fuzzer:fuzztest",
"getmissionsnapshot_fuzzer:fuzztest",
"getprocessrunninginfos_fuzzer:fuzztest",
"gettopability_fuzzer:fuzztest",
"getwantsender_fuzzer:fuzztest",
@@ -69,7 +75,9 @@ group("fuzztest") {
"schedulecommandabilitydone_fuzzer:fuzztest",
"scheduleconnectabilitydone_fuzzer:fuzztest",
"scheduledisconnectabilitydone_fuzzer:fuzztest",
"sendanrprocessid_fuzzer:fuzztest",
"sendresulttoability_fuzzer:fuzztest",
"setabilitycontroller_fuzzer:fuzztest",
"setmissionicon_fuzzer:fuzztest",
"setmissionlabel_fuzzer:fuzztest",
"startability_fuzzer:fuzztest",
@@ -0,0 +1,79 @@
# 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/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("CompleteFirstFrameDrawingFuzzTest") {
module_out_path = module_output_path
fuzz_config_file =
"${ability_runtime_test_path}/fuzztest/completefirstframedrawing_fuzzer"
include_dirs = [ "${ability_runtime_innerkits_path}/ability_manager/include" ]
cflags = [
"-g",
"-O0",
"-Wno-unused-variable",
"-fno-omit-frame-pointer",
]
sources = [ "completefirstframedrawing_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}/uri_permission:uri_permission_mgr",
"${ability_runtime_native_path}/ability/native:abilitykit_native",
"${ability_runtime_services_path}/abilitymgr:abilityms",
"//third_party/jsoncpp:jsoncpp",
]
external_deps = [
"ability_base:want",
"ability_base:zuri",
"bundle_framework:appexecfwk_base",
"c_utils:utils",
"eventhandler:libeventhandler",
"ipc:ipc_core",
"relational_store:native_dataability",
"relational_store:native_rdb",
"samgr:samgr_proxy",
]
if (ability_runtime_graphics) {
deps += []
external_deps += [
"i18n:intl_util",
"window_manager:libwm",
]
}
}
###############################################################################
group("fuzztest") {
testonly = true
deps = []
deps += [
# deps file
":CompleteFirstFrameDrawingFuzzTest",
]
}
###############################################################################
@@ -0,0 +1,100 @@
/*
* 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 "completefirstframedrawing_fuzzer.h"
#include <cstddef>
#include <cstdint>
#include "ability_manager_client.h"
#include "ability_record.h"
using namespace OHOS::AAFwk;
using namespace OHOS::AppExecFwk;
namespace OHOS {
namespace {
constexpr size_t FOO_MAX_LEN = 1024;
}
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)
{
auto abilitymgr = AbilityManagerClient::GetInstance();
if (!abilitymgr) {
return false;
}
// get token and connectCallback
sptr<IRemoteObject> abilityToken = GetFuzzAbilityToken();
if (!abilityToken) {
std::cout << "Get ability token failed." << std::endl;
return false;
}
abilitymgr->CompleteFirstFrameDrawing(abilityToken);
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 == 0 || size > OHOS::FOO_MAX_LEN) {
std::cout << "invalid size" << std::endl;
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_COMPLETEFIRSTFRAMEDRAWING_FUZZER_H
#define FUZZTEST_OHOS_ABILITY_RUNTIME_COMPLETEFIRSTFRAMEDRAWING_FUZZER_H
#define FUZZ_PROJECT_NAME "completefirstframedrawing_fuzzer"
#endif
@@ -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
@@ -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>
@@ -0,0 +1,78 @@
# 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/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("DelegatorDoAbilityBackgroundFuzzTest") {
module_out_path = module_output_path
fuzz_config_file = "${ability_runtime_test_path}/fuzztest/delegatordoabilitybackground_fuzzer"
include_dirs = [ "${ability_runtime_innerkits_path}/ability_manager/include" ]
cflags = [
"-g",
"-O0",
"-Wno-unused-variable",
"-fno-omit-frame-pointer",
]
sources = [ "delegatordoabilitybackground_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}/uri_permission:uri_permission_mgr",
"${ability_runtime_native_path}/ability/native:abilitykit_native",
"${ability_runtime_services_path}/abilitymgr:abilityms",
"//third_party/jsoncpp:jsoncpp",
]
external_deps = [
"ability_base:want",
"ability_base:zuri",
"bundle_framework:appexecfwk_base",
"c_utils:utils",
"eventhandler:libeventhandler",
"ipc:ipc_core",
"relational_store:native_dataability",
"relational_store:native_rdb",
"samgr:samgr_proxy",
]
if (ability_runtime_graphics) {
deps += []
external_deps += [
"i18n:intl_util",
"window_manager:libwm",
]
}
}
###############################################################################
group("fuzztest") {
testonly = true
deps = []
deps += [
# deps file
":DelegatorDoAbilityBackgroundFuzzTest",
]
}
###############################################################################
@@ -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
@@ -0,0 +1,107 @@
/*
* 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 "delegatordoabilitybackground_fuzzer.h"
#include <cstddef>
#include <cstdint>
#include "ability_manager_client.h"
#include "ability_record.h"
using namespace OHOS::AAFwk;
using namespace OHOS::AppExecFwk;
namespace OHOS {
namespace {
constexpr size_t FOO_MAX_LEN = 1024;
}
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;
}
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)
{
auto abilitymgr = AbilityManagerClient::GetInstance();
if (!abilitymgr) {
return false;
}
// get token and connectCallback
sptr<IRemoteObject> token = GetFuzzAbilityToken();
if (!token) {
std::cout << "Get ability token failed." << std::endl;
return false;
}
if (abilitymgr->DelegatorDoAbilityBackground(token) != 0) {
return false;
}
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 == 0 || size > OHOS::FOO_MAX_LEN) {
std::cout << "invalid size" << std::endl;
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_DELEGATORDOABILITYBACKGROUND_FUZZER_H
#define FUZZTEST_OHOS_ABILITY_RUNTIME_DELEGATORDOABILITYBACKGROUND_FUZZER_H
#define FUZZ_PROJECT_NAME "delegatordoabilitybackground_fuzzer"
#endif
@@ -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>
@@ -0,0 +1,78 @@
# 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/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("DelegatorDoAbilityForegroundFuzzTest") {
module_out_path = module_output_path
fuzz_config_file = "${ability_runtime_test_path}/fuzztest/delegatordoabilityforeground_fuzzer"
include_dirs = [ "${ability_runtime_innerkits_path}/ability_manager/include" ]
cflags = [
"-g",
"-O0",
"-Wno-unused-variable",
"-fno-omit-frame-pointer",
]
sources = [ "delegatordoabilityforeground_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}/uri_permission:uri_permission_mgr",
"${ability_runtime_native_path}/ability/native:abilitykit_native",
"${ability_runtime_services_path}/abilitymgr:abilityms",
"//third_party/jsoncpp:jsoncpp",
]
external_deps = [
"ability_base:want",
"ability_base:zuri",
"bundle_framework:appexecfwk_base",
"c_utils:utils",
"eventhandler:libeventhandler",
"ipc:ipc_core",
"relational_store:native_dataability",
"relational_store:native_rdb",
"samgr:samgr_proxy",
]
if (ability_runtime_graphics) {
deps += []
external_deps += [
"i18n:intl_util",
"window_manager:libwm",
]
}
}
###############################################################################
group("fuzztest") {
testonly = true
deps = []
deps += [
# deps file
":DelegatorDoAbilityForegroundFuzzTest",
]
}
###############################################################################
@@ -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
@@ -0,0 +1,107 @@
/*
* 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 "delegatordoabilityforeground_fuzzer.h"
#include <cstddef>
#include <cstdint>
#include "ability_manager_client.h"
#include "ability_record.h"
using namespace OHOS::AAFwk;
using namespace OHOS::AppExecFwk;
namespace OHOS {
namespace {
constexpr size_t FOO_MAX_LEN = 1024;
}
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;
}
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)
{
auto abilitymgr = AbilityManagerClient::GetInstance();
if (!abilitymgr) {
return false;
}
// get token and connectCallback
sptr<IRemoteObject> token = GetFuzzAbilityToken();
if (!token) {
std::cout << "Get ability token failed." << std::endl;
return false;
}
if (abilitymgr->DelegatorDoAbilityForeground(token) != 0) {
return false;
}
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 == 0 || size > OHOS::FOO_MAX_LEN) {
std::cout << "invalid size" << std::endl;
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_DELEGATORDOABILITYFOREGROUND_FUZZER_H
#define FUZZTEST_OHOS_ABILITY_RUNTIME_DELEGATORDOABILITYFOREGROUND_FUZZER_H
#define FUZZ_PROJECT_NAME "delegatordoabilityforeground_fuzzer"
#endif
@@ -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>
@@ -0,0 +1,78 @@
# 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/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("DoAbilityBackgroundFuzzTest") {
module_out_path = module_output_path
fuzz_config_file =
"${ability_runtime_test_path}/fuzztest/doabilitybackground_fuzzer"
include_dirs = [ "${ability_runtime_innerkits_path}/ability_manager/include" ]
cflags = [
"-g",
"-O0",
"-Wno-unused-variable",
"-fno-omit-frame-pointer",
]
sources = [ "doabilitybackground_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}/uri_permission:uri_permission_mgr",
"${ability_runtime_native_path}/ability/native:abilitykit_native",
"${ability_runtime_services_path}/abilitymgr:abilityms",
]
external_deps = [
"ability_base:want",
"ability_base:zuri",
"bundle_framework:appexecfwk_base",
"c_utils:utils",
"eventhandler:libeventhandler",
"ipc:ipc_core",
"relational_store:native_dataability",
"relational_store:native_rdb",
"samgr:samgr_proxy",
]
if (ability_runtime_graphics) {
deps += []
external_deps += [
"i18n:intl_util",
"window_manager:libwm",
]
}
}
###############################################################################
group("fuzztest") {
testonly = true
deps = []
deps += [
# deps file
":DoAbilityBackgroundFuzzTest",
]
}
###############################################################################
@@ -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
@@ -0,0 +1,108 @@
/*
* 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 "doabilitybackground_fuzzer.h"
#include <cstddef>
#include <cstdint>
#include "ability_manager_client.h"
#include "ability_record.h"
using namespace OHOS::AAFwk;
using namespace OHOS::AppExecFwk;
namespace OHOS {
namespace {
constexpr size_t FOO_MAX_LEN = 1024;
}
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];
}
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)
{
auto abilitymgr = AbilityManagerClient::GetInstance();
if (!abilitymgr) {
return false;
}
// get token and connectCallback
sptr<IRemoteObject> token = GetFuzzAbilityToken();
uint32_t flag = GetU32Data(data);
if (!token) {
std::cout << "Get ability token failed." << std::endl;
return false;
}
if (abilitymgr->DoAbilityBackground(token, flag) != 0) {
return false;
}
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 == 0 || size > OHOS::FOO_MAX_LEN) {
std::cout << "invalid size" << std::endl;
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_DOABILITYBACKGROUND_FUZZER_H
#define FUZZTEST_OHOS_ABILITY_RUNTIME_DOABILITYBACKGROUND_FUZZER_H
#define FUZZ_PROJECT_NAME "doabilitybackground_fuzzer"
#endif
@@ -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>
@@ -0,0 +1,78 @@
# 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/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("DoAbilityForegroundFuzzTest") {
module_out_path = module_output_path
fuzz_config_file =
"${ability_runtime_test_path}/fuzztest/doabilityforeground_fuzzer"
include_dirs = [ "${ability_runtime_innerkits_path}/ability_manager/include" ]
cflags = [
"-g",
"-O0",
"-Wno-unused-variable",
"-fno-omit-frame-pointer",
]
sources = [ "doabilityforeground_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}/uri_permission:uri_permission_mgr",
"${ability_runtime_native_path}/ability/native:abilitykit_native",
"${ability_runtime_services_path}/abilitymgr:abilityms",
]
external_deps = [
"ability_base:want",
"ability_base:zuri",
"bundle_framework:appexecfwk_base",
"c_utils:utils",
"eventhandler:libeventhandler",
"ipc:ipc_core",
"relational_store:native_dataability",
"relational_store:native_rdb",
"samgr:samgr_proxy",
]
if (ability_runtime_graphics) {
deps += []
external_deps += [
"i18n:intl_util",
"window_manager:libwm",
]
}
}
###############################################################################
group("fuzztest") {
testonly = true
deps = []
deps += [
# deps file
":DoAbilityForegroundFuzzTest",
]
}
###############################################################################
@@ -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
@@ -0,0 +1,108 @@
/*
* 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 "doabilityforeground_fuzzer.h"
#include <cstddef>
#include <cstdint>
#include "ability_manager_client.h"
#include "ability_record.h"
using namespace OHOS::AAFwk;
using namespace OHOS::AppExecFwk;
namespace OHOS {
namespace {
constexpr size_t FOO_MAX_LEN = 1024;
}
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];
}
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)
{
auto abilitymgr = AbilityManagerClient::GetInstance();
if (!abilitymgr) {
return false;
}
// get token and connectCallback
sptr<IRemoteObject> token = GetFuzzAbilityToken();
uint32_t flag = GetU32Data(data);
if (!token) {
std::cout << "Get ability token failed." << std::endl;
return false;
}
if (abilitymgr->DoAbilityForeground(token, flag) != 0) {
return false;
}
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 == 0 || size > OHOS::FOO_MAX_LEN) {
std::cout << "invalid size" << std::endl;
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_DOABILITYFOREGROUND_FUZZER_H
#define FUZZTEST_OHOS_ABILITY_RUNTIME_DOABILITYFOREGROUND_FUZZER_H
#define FUZZ_PROJECT_NAME "doabilityforeground_fuzzer"
#endif
@@ -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>
@@ -0,0 +1,79 @@
# 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/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("GetMissionSnapshotFuzzTest") {
module_out_path = module_output_path
fuzz_config_file =
"${ability_runtime_test_path}/fuzztest/getmissionsnapshot_fuzzer"
include_dirs = [ "${ability_runtime_innerkits_path}/ability_manager/include" ]
cflags = [
"-g",
"-O0",
"-Wno-unused-variable",
"-fno-omit-frame-pointer",
]
sources = [ "getmissionsnapshot_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}/uri_permission:uri_permission_mgr",
"${ability_runtime_native_path}/ability/native:abilitykit_native",
"${ability_runtime_services_path}/abilitymgr:abilityms",
"//third_party/jsoncpp:jsoncpp",
]
external_deps = [
"ability_base:want",
"ability_base:zuri",
"bundle_framework:appexecfwk_base",
"c_utils:utils",
"eventhandler:libeventhandler",
"ipc:ipc_core",
"relational_store:native_dataability",
"relational_store:native_rdb",
"samgr:samgr_proxy",
]
if (ability_runtime_graphics) {
deps += []
external_deps += [
"i18n:intl_util",
"window_manager:libwm",
]
}
}
###############################################################################
group("fuzztest") {
testonly = true
deps = []
deps += [
# deps file
":GetMissionSnapshotFuzzTest",
]
}
###############################################################################
@@ -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
@@ -0,0 +1,90 @@
/*
* 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 "getmissionsnapshot_fuzzer.h"
#include <cstddef>
#include <cstdint>
#include "ability_manager_client.h"
#include "ability_record.h"
using namespace OHOS::AAFwk;
using namespace OHOS::AppExecFwk;
namespace OHOS {
namespace {
constexpr size_t FOO_MAX_LEN = 1024;
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)
{
auto abilitymgr = AbilityManagerClient::GetInstance();
if (!abilitymgr) {
return false;
}
std::string deviceId(data, size);
int32_t missionId = static_cast<int32_t>(GetU32Data(data));
MissionSnapshot snapshot;
bool isLowResolution = *data % ENABLE;
if (abilitymgr->GetMissionSnapshot(deviceId, missionId, snapshot, isLowResolution) != 0) {
return false;
}
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 == 0 || size > OHOS::FOO_MAX_LEN) {
std::cout << "invalid size" << std::endl;
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_GETMISSIONSNAPSHOT_FUZZER_H
#define FUZZTEST_OHOS_ABILITY_RUNTIME_GETMISSIONSNAPSHOT_FUZZER_H
#define FUZZ_PROJECT_NAME "getmissionsnapshot_fuzzer"
#endif
@@ -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>
@@ -41,6 +41,7 @@ ohos_fuzztest("GetTopAbilityFuzzTest") {
deps = [
"${ability_runtime_innerkits_path}/ability_manager:ability_manager",
"${ability_runtime_innerkits_path}/app_manager:app_manager",
"${ability_runtime_services_path}/abilitymgr:abilityms",
]
external_deps = [
@@ -49,6 +50,7 @@ ohos_fuzztest("GetTopAbilityFuzzTest") {
"appspawn:appspawn_socket_client",
"bundle_framework:appexecfwk_base",
"ipc:ipc_core",
"relational_store:native_dataability",
]
}
@@ -19,23 +19,50 @@
#include <cstdint>
#include "ability_manager_client.h"
#include "ability_record.h"
using namespace OHOS::AAFwk;
using namespace OHOS::AppExecFwk;
namespace OHOS {
constexpr size_t FOO_MAX_LEN = 1024;
bool DoSomethingInterestingWithMyAPI(const char* data, size_t size)
{
AbilityManagerClient* abilityMgrClient = new AbilityManagerClient();
if (!abilityMgrClient) {
return false;
}
sptr<Token> GetFuzzAbilityToken()
{
sptr<Token> token = nullptr;
abilityMgrClient->GetTopAbility();
return true;
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)
{
auto abilitymgr = AbilityManagerClient::GetInstance();
if (!abilitymgr) {
return false;
}
abilitymgr->GetTopAbility();
// get token and connectCallback
sptr<IRemoteObject> token = GetFuzzAbilityToken();
if (!token) {
std::cout << "Get ability token failed." << std::endl;
return false;
}
if (abilitymgr->GetTopAbility(token) != 0) {
return false;
}
return true;
}
}
/* Fuzzer entry point */
@@ -0,0 +1,79 @@
# 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/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("SendANRProcessIDFuzzTest") {
module_out_path = module_output_path
fuzz_config_file =
"${ability_runtime_test_path}/fuzztest/sendanrprocessid_fuzzer"
include_dirs = [ "${ability_runtime_innerkits_path}/ability_manager/include" ]
cflags = [
"-g",
"-O0",
"-Wno-unused-variable",
"-fno-omit-frame-pointer",
]
sources = [ "sendanrprocessid_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}/uri_permission:uri_permission_mgr",
"${ability_runtime_native_path}/ability/native:abilitykit_native",
"${ability_runtime_services_path}/abilitymgr:abilityms",
"//third_party/jsoncpp:jsoncpp",
]
external_deps = [
"ability_base:want",
"ability_base:zuri",
"bundle_framework:appexecfwk_base",
"c_utils:utils",
"eventhandler:libeventhandler",
"ipc:ipc_core",
"relational_store:native_dataability",
"relational_store:native_rdb",
"samgr:samgr_proxy",
]
if (ability_runtime_graphics) {
deps += []
external_deps += [
"i18n:intl_util",
"window_manager:libwm",
]
}
}
###############################################################################
group("fuzztest") {
testonly = true
deps = []
deps += [
# deps file
":SendANRProcessIDFuzzTest",
]
}
###############################################################################
@@ -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
@@ -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>
@@ -0,0 +1,85 @@
/*
* 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 "sendanrprocessid_fuzzer.h"
#include <cstddef>
#include <cstdint>
#include "ability_manager_client.h"
using namespace OHOS::AAFwk;
using namespace OHOS::AppExecFwk;
namespace OHOS {
namespace {
constexpr size_t FOO_MAX_LEN = 1024;
}
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)
{
auto abilitymgr = AbilityManagerClient::GetInstance();
if (!abilitymgr) {
return false;
}
int pid = static_cast<int>(GetU32Data(data));
if (abilitymgr->SendANRProcessID(pid) != 0) {
return false;
}
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 == 0 || size > OHOS::FOO_MAX_LEN) {
std::cout << "invalid size" << std::endl;
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_SENDANRPROCESSID_FUZZER_H
#define FUZZTEST_OHOS_ABILITY_RUNTIME_SENDANRPROCESSID_FUZZER_H
#define FUZZ_PROJECT_NAME "sendanrprocessid_fuzzer"
#endif
@@ -0,0 +1,79 @@
# 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/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("SetAbilityControllerFuzzTest") {
module_out_path = module_output_path
fuzz_config_file =
"${ability_runtime_test_path}/fuzztest/setabilitycontroller_fuzzer"
include_dirs = [ "${ability_runtime_innerkits_path}/ability_manager/include" ]
cflags = [
"-g",
"-O0",
"-Wno-unused-variable",
"-fno-omit-frame-pointer",
]
sources = [ "setabilitycontroller_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}/uri_permission:uri_permission_mgr",
"${ability_runtime_native_path}/ability/native:abilitykit_native",
"${ability_runtime_services_path}/abilitymgr:abilityms",
"//third_party/jsoncpp:jsoncpp",
]
external_deps = [
"ability_base:want",
"ability_base:zuri",
"bundle_framework:appexecfwk_base",
"c_utils:utils",
"eventhandler:libeventhandler",
"ipc:ipc_core",
"relational_store:native_dataability",
"relational_store:native_rdb",
"samgr:samgr_proxy",
]
if (ability_runtime_graphics) {
deps += []
external_deps += [
"i18n:intl_util",
"window_manager:libwm",
]
}
}
###############################################################################
group("fuzztest") {
testonly = true
deps = []
deps += [
# deps file
":SetAbilityControllerFuzzTest",
]
}
###############################################################################
@@ -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
@@ -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>
@@ -0,0 +1,91 @@
/*
* 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 "setabilitycontroller_fuzzer.h"
#include <cstddef>
#include <cstdint>
#include "ability_manager_client.h"
#include "ability_record.h"
#include "iability_controller.h"
using namespace OHOS::AAFwk;
using namespace OHOS::AppExecFwk;
namespace OHOS {
namespace {
constexpr size_t FOO_MAX_LEN = 1024;
constexpr uint8_t ENABLE = 2;
}
class AbilityControllerFuzz : public IRemoteStub<IAbilityController> {
public:
AbilityControllerFuzz();
virtual ~AbilityControllerFuzz();
virtual bool AllowAbilityStart(const Want &want, const std::string &bundleName) override;
virtual bool AllowAbilityBackground(const std::string &bundleName) override;
};
bool DoSomethingInterestingWithMyAPI(const char* data, size_t size)
{
auto abilitymgr = AbilityManagerClient::GetInstance();
if (!abilitymgr) {
return false;
}
sptr<AbilityControllerFuzz> abilityController;
bool imAStabilityTest = *data % ENABLE;
if (abilitymgr->SetAbilityController(abilityController, imAStabilityTest) != 0) {
return false;
}
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 == 0 || size > OHOS::FOO_MAX_LEN) {
std::cout << "invalid size" << std::endl;
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_SETABILITYCONTROLLER_FUZZER_H
#define FUZZTEST_OHOS_ABILITY_RUNTIME_SETABILITYCONTROLLER_FUZZER_H
#define FUZZ_PROJECT_NAME "setabilitycontroller_fuzzer"
#endif