!3470 补充FUZZ测试套

Merge pull request !3470 from 周士成/master
This commit is contained in:
openharmony_ci
2022-10-21 06:55:04 +00:00
committed by Gitee
37 changed files with 1287 additions and 6 deletions
+6
View File
@@ -32,6 +32,9 @@ group("fuzztest") {
"getwantsender_fuzzer:fuzztest",
"killprocesswithaccount_fuzzer:fuzztest",
"missionlistenerstub_fuzzer:fuzztest",
"registerabilitylifecyclecallback_fuzzer:fuzztest",
"registerapplicationstateobserver_fuzzer:fuzztest",
"registerenvironmentcallback_fuzzer:fuzztest",
"remotemissionlistenerstub_fuzzer:fuzztest",
"setmissionicon_fuzzer:fuzztest",
"setmissionlabel_fuzzer:fuzztest",
@@ -42,6 +45,9 @@ group("fuzztest") {
"stopserviceability_fuzzer:fuzztest",
"stopserviceextensionability_fuzzer:fuzztest",
"terminateability_fuzzer:fuzztest",
"unregisterabilitylifecyclecallback_fuzzer:fuzztest",
"unregisterapplicationstateobserver_fuzzer:fuzztest",
"unregisterenvironmentcallback_fuzzer:fuzztest",
"updateconfiguration_fuzzer:fuzztest",
"uripermissionmanager_fuzzer:fuzztest",
"wantagenthelperstring_fuzzer:fuzztest",
+1 -1
View File
@@ -16,7 +16,7 @@ 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"
module_output_path = "ability_runtime/ability_context_native"
##############################fuzztest##########################################
ohos_fuzztest("ConnectAbilityFuzzTest") {
@@ -16,7 +16,7 @@ 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"
module_output_path = "ability_runtime/ability_context_native"
##############################fuzztest##########################################
ohos_fuzztest("DisconnectAbilityFuzzTest") {
@@ -16,7 +16,7 @@ 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"
module_output_path = "ability_runtime/libappms"
##############################fuzztest##########################################
ohos_fuzztest("KillProcessWithAccountFuzzTest") {
@@ -0,0 +1,57 @@
# 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/app_context"
##############################fuzztest##########################################
ohos_fuzztest("RegisterAbilityLifecycleCallbackFuzzTest") {
module_out_path = module_output_path
fuzz_config_file = "${ability_runtime_test_path}/fuzztest/registerabilitylifecyclecallback_fuzzer"
include_dirs = [ "${ability_runtime_path}/interfaces/kits/native/appkit/ability_runtime/context" ]
cflags = [
"-g",
"-O0",
"-Wno-unused-variable",
"-fno-omit-frame-pointer",
]
sources = [ "registerabilitylifecyclecallback_fuzzer.cpp" ]
configs = [ "${ability_runtime_innerkits_path}/ability_manager:ability_manager_public_config" ]
deps = [ "${ability_runtime_native_path}/appkit:app_context" ]
external_deps = [
"ability_base:want",
"c_utils:utils",
]
}
###############################################################################
group("fuzztest") {
testonly = true
deps = []
deps += [
# deps file
":RegisterAbilityLifecycleCallbackFuzzTest",
]
}
###############################################################################
@@ -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) 2021 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,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 "registerabilitylifecyclecallback_fuzzer.h"
#include <cstddef>
#include <cstdint>
#include "ability_lifecycle_callback.h"
#include "application_context.h"
#include "securec.h"
using namespace OHOS::AAFwk;
using namespace OHOS::AppExecFwk;
using namespace OHOS::AbilityRuntime;
namespace OHOS {
constexpr size_t FOO_MAX_LEN = 1024;
class AbilityLifecycleCallbackFuzz : public AbilityLifecycleCallback {
public:
explicit AbilityLifecycleCallbackFuzz() {};
virtual ~AbilityLifecycleCallbackFuzz() {};
void OnAbilityCreate(const std::shared_ptr<NativeReference> &ability) override {};
void OnWindowStageCreate(const std::shared_ptr<NativeReference> &ability,
const std::shared_ptr<NativeReference> &windowStage) override {};
void OnWindowStageDestroy(const std::shared_ptr<NativeReference> &ability,
const std::shared_ptr<NativeReference> &windowStage) override {};
void OnWindowStageActive(const std::shared_ptr<NativeReference> &ability,
const std::shared_ptr<NativeReference> &windowStage) override {};
void OnWindowStageInactive(const std::shared_ptr<NativeReference> &ability,
const std::shared_ptr<NativeReference> &windowStage) override {};
void OnAbilityDestroy(const std::shared_ptr<NativeReference> &ability) override {};
void OnAbilityForeground(const std::shared_ptr<NativeReference> &ability) override {};
void OnAbilityBackground(const std::shared_ptr<NativeReference> &ability) override {};
void OnAbilityContinue(const std::shared_ptr<NativeReference> &ability) override {};
};
bool DoSomethingInterestingWithMyAPI(const char* data, size_t size)
{
ApplicationContext* context = new ApplicationContext();
if (!context) {
return false;
}
std::shared_ptr<AbilityLifecycleCallbackFuzz> callback;
context->RegisterAbilityLifecycleCallback(callback);
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,20 @@
/*
* 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_REGISTERABILITYLIFECYCLECALLBACK_FUZZER_H
#define FUZZTEST_OHOS_ABILITY_RUNTIME_REGISTERABILITYLIFECYCLECALLBACK_FUZZER_H
#define FUZZ_PROJECT_NAME "registerabilitylifecyclecallback_fuzzer"
#endif
@@ -0,0 +1,75 @@
# 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/libappms"
##############################fuzztest##########################################
ohos_fuzztest("RegisterApplicationStateObserverFuzzTest") {
module_out_path = module_output_path
fuzz_config_file = "${ability_runtime_test_path}/fuzztest/registerapplicationstateobserver_fuzzer"
include_dirs = [ "${ability_runtime_innerkits_path}/ability_manager/include" ]
cflags = [
"-g",
"-O0",
"-Wno-unused-variable",
"-fno-omit-frame-pointer",
]
sources = [ "registerapplicationstateobserver_fuzzer.cpp" ]
configs = [ "${ability_runtime_services_path}/appmgr:appmgr_config" ]
deps = [
"${ability_runtime_innerkits_path}/uri_permission:uri_permission_mgr",
"${ability_runtime_services_path}/appmgr:libappms",
]
external_deps = [
"ability_base:base",
"ability_runtime:ability_deps_wrapper",
"ability_runtime:app_manager",
"appspawn:appspawn_socket_client",
"bundle_framework:appexecfwk_base",
"bundle_framework:appexecfwk_core",
"eventhandler:libeventhandler",
"init:libbeget_proxy",
"init:libbegetutil",
"ipc:ipc_core",
"safwk:system_ability_fwk",
"samgr:samgr_proxy",
]
if (ability_runtime_graphics) {
deps += []
external_deps += [
"i18n:intl_util",
"window_manager:libwm",
]
}
}
###############################################################################
group("fuzztest") {
testonly = true
deps = []
deps += [
# deps file
":RegisterApplicationStateObserverFuzzTest",
]
}
###############################################################################
@@ -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,86 @@
/*
* 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 "registerapplicationstateobserver_fuzzer.h"
#include <cstddef>
#include <cstdint>
#define private public
#include "app_mgr_service.h"
#undef private
#include "iapplication_state_observer.h"
#include "securec.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)
{
std::shared_ptr<AppMgrService> appMgrService = std::make_shared<AppMgrService>();
if (!appMgrService) {
return false;
}
sptr<IApplicationStateObserver> observer;
std::vector<std::string> bundleNameList;
std::string bundleName(data);
bundleNameList.emplace_back(bundleName);
if (appMgrService->RegisterApplicationStateObserver(observer, bundleNameList) != 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_REGISTERAPPLICATIONSTATEOBSERVER_FUZZER_H
#define FUZZTEST_OHOS_ABILITY_RUNTIME_REGISTERAPPLICATIONSTATEOBSERVER_FUZZER_H
#define FUZZ_PROJECT_NAME "registerapplicationstateobserver_fuzzer"
#endif
@@ -0,0 +1,58 @@
# 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/app_context"
##############################fuzztest##########################################
ohos_fuzztest("RegisterEnvironmentCallbackFuzzTest") {
module_out_path = module_output_path
fuzz_config_file =
"${ability_runtime_test_path}/fuzztest/registerenvironmentcallback_fuzzer"
include_dirs = [ "${ability_runtime_path}/interfaces/kits/native/appkit/ability_runtime/context" ]
cflags = [
"-g",
"-O0",
"-Wno-unused-variable",
"-fno-omit-frame-pointer",
]
sources = [ "registerenvironmentcallback_fuzzer.cpp" ]
configs = [ "${ability_runtime_innerkits_path}/ability_manager:ability_manager_public_config" ]
deps = [ "${ability_runtime_native_path}/appkit:app_context" ]
external_deps = [
"ability_base:want",
"c_utils:utils",
]
}
###############################################################################
group("fuzztest") {
testonly = true
deps = []
deps += [
# deps file
":RegisterEnvironmentCallbackFuzzTest",
]
}
###############################################################################
@@ -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) 2021 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,84 @@
/*
* 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 "registerenvironmentcallback_fuzzer.h"
#include <cstddef>
#include <cstdint>
#include "environment_callback.h"
#include "application_context.h"
#include "securec.h"
using namespace OHOS::AAFwk;
using namespace OHOS::AppExecFwk;
using namespace OHOS::AbilityRuntime;
namespace OHOS {
constexpr size_t FOO_MAX_LEN = 1024;
class EnvironmentCallbackFuzz : public EnvironmentCallback {
public:
explicit EnvironmentCallbackFuzz() {};
void OnConfigurationUpdated(const AppExecFwk::Configuration &config) override {};
void OnMemoryLevel(const int level) override {};
};
bool DoSomethingInterestingWithMyAPI(const char* data, size_t size)
{
ApplicationContext* context = new ApplicationContext();
if (!context) {
return false;
}
std::shared_ptr<EnvironmentCallbackFuzz> callback;
context->RegisterEnvironmentCallback(callback);
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,20 @@
/*
* 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_REGISTERENVIRONMENTCALLBACK_FUZZER_H
#define FUZZTEST_OHOS_ABILITY_RUNTIME_REGISTERENVIRONMENTCALLBACK_FUZZER_H
#define FUZZ_PROJECT_NAME "registerenvironmentcallback_fuzzer"
#endif
@@ -16,7 +16,7 @@ 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"
module_output_path = "ability_runtime/ability_context_native"
##############################fuzztest##########################################
ohos_fuzztest("StartServiceExtensionAbilityFuzzTest") {
@@ -16,7 +16,7 @@ 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"
module_output_path = "ability_runtime/ability_context_native"
##############################fuzztest##########################################
ohos_fuzztest("StopServiceExtensionAbilityFuzzTest") {
@@ -16,7 +16,7 @@ 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"
module_output_path = "ability_runtime/ability_context_native"
##############################fuzztest##########################################
ohos_fuzztest("TerminateAbilityFuzzTest") {
@@ -0,0 +1,57 @@
# 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/app_context"
##############################fuzztest##########################################
ohos_fuzztest("UnregisterAbilityLifecycleCallbackFuzzTest") {
module_out_path = module_output_path
fuzz_config_file = "${ability_runtime_test_path}/fuzztest/unregisterabilitylifecyclecallback_fuzzer"
include_dirs = [ "${ability_runtime_path}/interfaces/kits/native/appkit/ability_runtime/context" ]
cflags = [
"-g",
"-O0",
"-Wno-unused-variable",
"-fno-omit-frame-pointer",
]
sources = [ "unregisterabilitylifecyclecallback_fuzzer.cpp" ]
configs = [ "${ability_runtime_innerkits_path}/ability_manager:ability_manager_public_config" ]
deps = [ "${ability_runtime_native_path}/appkit:app_context" ]
external_deps = [
"ability_base:want",
"c_utils:utils",
]
}
###############################################################################
group("fuzztest") {
testonly = true
deps = []
deps += [
# deps file
":UnregisterAbilityLifecycleCallbackFuzzTest",
]
}
###############################################################################
@@ -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) 2021 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,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 "unregisterabilitylifecyclecallback_fuzzer.h"
#include <cstddef>
#include <cstdint>
#include "ability_lifecycle_callback.h"
#include "application_context.h"
#include "securec.h"
using namespace OHOS::AAFwk;
using namespace OHOS::AppExecFwk;
using namespace OHOS::AbilityRuntime;
namespace OHOS {
constexpr size_t FOO_MAX_LEN = 1024;
class AbilityLifecycleCallbackFuzz : public AbilityLifecycleCallback {
public:
explicit AbilityLifecycleCallbackFuzz() {};
virtual ~AbilityLifecycleCallbackFuzz() {};
void OnAbilityCreate(const std::shared_ptr<NativeReference> &ability) override {};
void OnWindowStageCreate(const std::shared_ptr<NativeReference> &ability,
const std::shared_ptr<NativeReference> &windowStage) override {};
void OnWindowStageDestroy(const std::shared_ptr<NativeReference> &ability,
const std::shared_ptr<NativeReference> &windowStage) override {};
void OnWindowStageActive(const std::shared_ptr<NativeReference> &ability,
const std::shared_ptr<NativeReference> &windowStage) override {};
void OnWindowStageInactive(const std::shared_ptr<NativeReference> &ability,
const std::shared_ptr<NativeReference> &windowStage) override {};
void OnAbilityDestroy(const std::shared_ptr<NativeReference> &ability) override {};
void OnAbilityForeground(const std::shared_ptr<NativeReference> &ability) override {};
void OnAbilityBackground(const std::shared_ptr<NativeReference> &ability) override {};
void OnAbilityContinue(const std::shared_ptr<NativeReference> &ability) override {};
};
bool DoSomethingInterestingWithMyAPI(const char* data, size_t size)
{
ApplicationContext* context = new ApplicationContext();
if (!context) {
return false;
}
std::shared_ptr<AbilityLifecycleCallbackFuzz> callback;
context->UnregisterAbilityLifecycleCallback(callback);
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,20 @@
/*
* 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_UNREGISTERABILITYLIFECYCLECALLBACK_FUZZER_H
#define FUZZTEST_OHOS_ABILITY_RUNTIME_UNREGISTERABILITYLIFECYCLECALLBACK_FUZZER_H
#define FUZZ_PROJECT_NAME "unregisterabilitylifecyclecallback_fuzzer"
#endif
@@ -0,0 +1,75 @@
# 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/libappms"
##############################fuzztest##########################################
ohos_fuzztest("UnregisterApplicationStateObserverFuzzTest") {
module_out_path = module_output_path
fuzz_config_file = "${ability_runtime_test_path}/fuzztest/unregisterapplicationstateobserver_fuzzer"
include_dirs = [ "${ability_runtime_innerkits_path}/ability_manager/include" ]
cflags = [
"-g",
"-O0",
"-Wno-unused-variable",
"-fno-omit-frame-pointer",
]
sources = [ "unregisterapplicationstateobserver_fuzzer.cpp" ]
configs = [ "${ability_runtime_services_path}/appmgr:appmgr_config" ]
deps = [
"${ability_runtime_innerkits_path}/uri_permission:uri_permission_mgr",
"${ability_runtime_services_path}/appmgr:libappms",
]
external_deps = [
"ability_base:base",
"ability_runtime:ability_deps_wrapper",
"ability_runtime:app_manager",
"appspawn:appspawn_socket_client",
"bundle_framework:appexecfwk_base",
"bundle_framework:appexecfwk_core",
"eventhandler:libeventhandler",
"init:libbeget_proxy",
"init:libbegetutil",
"ipc:ipc_core",
"safwk:system_ability_fwk",
"samgr:samgr_proxy",
]
if (ability_runtime_graphics) {
deps += []
external_deps += [
"i18n:intl_util",
"window_manager:libwm",
]
}
}
###############################################################################
group("fuzztest") {
testonly = true
deps = []
deps += [
# deps file
":UnregisterApplicationStateObserverFuzzTest",
]
}
###############################################################################
@@ -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,82 @@
/*
* 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 "unregisterapplicationstateobserver_fuzzer.h"
#include <cstddef>
#include <cstdint>
#define private public
#include "app_mgr_service.h"
#undef private
#include "iapplication_state_observer.h"
#include "securec.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)
{
std::shared_ptr<AppMgrService> appMgrService = std::make_shared<AppMgrService>();
sptr<IApplicationStateObserver> observer;
if (!appMgrService) {
return false;
}
if (appMgrService->UnregisterApplicationStateObserver(observer) != 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_UNREGISTERAPPLICATIONSTATEOBSERVER_FUZZER_H
#define FUZZTEST_OHOS_ABILITY_RUNTIME_UNREGISTERAPPLICATIONSTATEOBSERVER_FUZZER_H
#define FUZZ_PROJECT_NAME "unregisterapplicationstateobserver_fuzzer"
#endif
@@ -0,0 +1,57 @@
# 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/app_context"
##############################fuzztest##########################################
ohos_fuzztest("UnregisterEnvironmentCallbackFuzzTest") {
module_out_path = module_output_path
fuzz_config_file = "${ability_runtime_test_path}/fuzztest/unregisterenvironmentcallback_fuzzer"
include_dirs = [ "${ability_runtime_path}/interfaces/kits/native/appkit/ability_runtime/context" ]
cflags = [
"-g",
"-O0",
"-Wno-unused-variable",
"-fno-omit-frame-pointer",
]
sources = [ "unregisterenvironmentcallback_fuzzer.cpp" ]
configs = [ "${ability_runtime_innerkits_path}/ability_manager:ability_manager_public_config" ]
deps = [ "${ability_runtime_native_path}/appkit:app_context" ]
external_deps = [
"ability_base:want",
"c_utils:utils",
]
}
###############################################################################
group("fuzztest") {
testonly = true
deps = []
deps += [
# deps file
":UnregisterEnvironmentCallbackFuzzTest",
]
}
###############################################################################
@@ -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) 2021 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,84 @@
/*
* 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 "unregisterenvironmentcallback_fuzzer.h"
#include <cstddef>
#include <cstdint>
#include "environment_callback.h"
#include "application_context.h"
#include "securec.h"
using namespace OHOS::AAFwk;
using namespace OHOS::AppExecFwk;
using namespace OHOS::AbilityRuntime;
namespace OHOS {
constexpr size_t FOO_MAX_LEN = 1024;
class EnvironmentCallbackFuzz : public EnvironmentCallback {
public:
explicit EnvironmentCallbackFuzz() {};
void OnConfigurationUpdated(const AppExecFwk::Configuration &config) override {};
void OnMemoryLevel(const int level) override {};
};
bool DoSomethingInterestingWithMyAPI(const char* data, size_t size)
{
ApplicationContext* context = new ApplicationContext();
if (!context) {
return false;
}
std::shared_ptr<EnvironmentCallbackFuzz> callback;
context->UnregisterEnvironmentCallback(callback);
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,20 @@
/*
* 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_UNREGISTERENVIRONMENTCALLBACK_FUZZER_H
#define FUZZTEST_OHOS_ABILITY_RUNTIME_UNREGISTERENVIRONMENTCALLBACK_FUZZER_H
#define FUZZ_PROJECT_NAME "unregisterenvironmentcallback_fuzzer"
#endif