mirror of
https://github.com/openharmony/ability_ability_runtime.git
synced 2026-08-24 22:21:36 -04:00
Signed-off-by: xuzheheng <xuzheheng1@huawei.com> Change-Id: I43137e02af772cbda169b47fa7b15a8fcfcf63db
This commit is contained in:
@@ -29,6 +29,7 @@ group("fuzztest") {
|
||||
"acquiredataability_fuzzer:fuzztest",
|
||||
"addabilitystagedone_fuzzer:fuzztest",
|
||||
"amsmgrscheduler_fuzzer:fuzztest",
|
||||
"applicationanrlistener_fuzzer:fuzztest",
|
||||
"applifecycledeal_fuzzer:fuzztest",
|
||||
"appmanager_fuzzer:fuzztest",
|
||||
"appmgrrest_fuzzer:fuzztest",
|
||||
@@ -47,6 +48,7 @@ group("fuzztest") {
|
||||
"closeability_fuzzer:fuzztest",
|
||||
"completefirstframedrawing_fuzzer:fuzztest",
|
||||
"connectability_fuzzer:fuzztest",
|
||||
"connectionstatemanager_fuzzer:fuzztest",
|
||||
"continueability_fuzzer:fuzztest",
|
||||
"continuemission_fuzzer:fuzztest",
|
||||
"delegatordoabilitybackground_fuzzer:fuzztest",
|
||||
|
||||
+88
@@ -0,0 +1,88 @@
|
||||
# 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")
|
||||
import("//foundation/resourceschedule/background_task_mgr/bgtaskmgr.gni")
|
||||
module_output_path = "ability_runtime/abilitymgr"
|
||||
|
||||
##############################fuzztest##########################################
|
||||
ohos_fuzztest("ApplicationAnrListenerFuzzTest") {
|
||||
module_out_path = module_output_path
|
||||
|
||||
fuzz_config_file =
|
||||
"${ability_runtime_test_path}/fuzztest/applicationanrlistener_fuzzer"
|
||||
include_dirs = [
|
||||
"${ability_runtime_innerkits_path}/ability_manager/include",
|
||||
"${ability_runtime_innerkits_path}/dataobs_manager/include",
|
||||
"${bgtaskmgr_interfaces_path}/innerkits/include",
|
||||
"${multimodalinput_path}/interfaces/native/innerkits/event/include",
|
||||
]
|
||||
cflags = [
|
||||
"-g",
|
||||
"-O0",
|
||||
"-Wno-unused-variable",
|
||||
"-fno-omit-frame-pointer",
|
||||
]
|
||||
sources = [ "applicationanrlistener_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",
|
||||
"background_task_mgr:bgtaskmgr_innerkits",
|
||||
"bundle_framework:appexecfwk_base",
|
||||
"c_utils:utils",
|
||||
"common_event_service:cesfwk_core",
|
||||
"common_event_service:cesfwk_innerkits",
|
||||
"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
|
||||
":ApplicationAnrListenerFuzzTest",
|
||||
]
|
||||
}
|
||||
###############################################################################
|
||||
+224
@@ -0,0 +1,224 @@
|
||||
/*
|
||||
* 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 "applicationanrlistener_fuzzer.h"
|
||||
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
|
||||
#define private public
|
||||
#define protected public
|
||||
#include "ability_manager_service.h"
|
||||
#include "application_anr_listener.h"
|
||||
#include "atomic_service_status_callback.h"
|
||||
#include "atomic_service_status_callback_proxy.h"
|
||||
#include "background_task_observer.h"
|
||||
#include "call_container.h"
|
||||
#include "call_record.h"
|
||||
#include "caller_info.h"
|
||||
#include "free_install_manager.h"
|
||||
#undef protected
|
||||
#undef private
|
||||
|
||||
#include "ability_record.h"
|
||||
#include "continuous_task_callback_info.h"
|
||||
|
||||
using namespace OHOS::AAFwk;
|
||||
using namespace OHOS::AppExecFwk;
|
||||
|
||||
namespace OHOS {
|
||||
namespace {
|
||||
constexpr size_t FOO_MAX_LEN = 1024;
|
||||
constexpr size_t U32_AT_SIZE = 4;
|
||||
class MyAbilityConnection : public IAbilityConnection {
|
||||
public:
|
||||
MyAbilityConnection() = default;
|
||||
virtual ~MyAbilityConnection() = default;
|
||||
void OnAbilityConnectDone(
|
||||
const AppExecFwk::ElementName &element, const sptr<IRemoteObject> &remoteObject, int resultCode) override
|
||||
{}
|
||||
void OnAbilityDisconnectDone(const AppExecFwk::ElementName &element, int resultCode) override
|
||||
{}
|
||||
sptr<IRemoteObject> AsObject() override
|
||||
{
|
||||
return {};
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
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];
|
||||
}
|
||||
|
||||
std::shared_ptr<AbilityRecord> GetFuzzAbilityRecord()
|
||||
{
|
||||
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) {
|
||||
return nullptr;
|
||||
}
|
||||
return abilityRecord;
|
||||
}
|
||||
|
||||
sptr<Token> GetFuzzAbilityToken()
|
||||
{
|
||||
sptr<Token> token = nullptr;
|
||||
std::shared_ptr<AbilityRecord> abilityRecord = GetFuzzAbilityRecord();
|
||||
if (abilityRecord) {
|
||||
token = abilityRecord->GetToken();
|
||||
}
|
||||
return token;
|
||||
}
|
||||
|
||||
bool DoSomethingInterestingWithMyAPI(const char* data, size_t size)
|
||||
{
|
||||
int intParam = static_cast<int>(GetU32Data(data));
|
||||
int32_t int32Param = static_cast<int32_t>(GetU32Data(data));
|
||||
int64_t int64Param = static_cast<int64_t>(GetU32Data(data));
|
||||
std::string stringParam(data, size);
|
||||
Parcel wantParcel;
|
||||
Want *want = nullptr;
|
||||
if (wantParcel.WriteBuffer(data, size)) {
|
||||
want = Want::Unmarshalling(wantParcel);
|
||||
if (!want) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
sptr<IRemoteObject> token = GetFuzzAbilityToken();
|
||||
sptr<IAbilityConnection> connect = new MyAbilityConnection();
|
||||
std::vector<std::string> info;
|
||||
std::shared_ptr<AbilityRecord> targetService = GetFuzzAbilityRecord();
|
||||
|
||||
// fuzz for ApplicationAnrListener
|
||||
auto applicationAnrListener = std::make_shared<ApplicationAnrListener>();
|
||||
applicationAnrListener->OnAnr(int32Param);
|
||||
|
||||
// fuzz for FreeInstallManager
|
||||
auto abilityms = std::make_shared<AbilityManagerService>();
|
||||
std::weak_ptr<AbilityManagerService> amsWeakPtr{abilityms};
|
||||
auto freeInstallManager = std::make_shared<FreeInstallManager>(amsWeakPtr);
|
||||
freeInstallManager->IsTopAbility(token);
|
||||
freeInstallManager->StartFreeInstall(*want, int32Param, intParam, token);
|
||||
freeInstallManager->RemoteFreeInstall(*want, int32Param, intParam, token);
|
||||
freeInstallManager->BuildFreeInstallInfo(*want, int32Param, intParam, token);
|
||||
freeInstallManager->StartRemoteFreeInstall(*want, intParam, int32Param, token);
|
||||
freeInstallManager->NotifyDmsCallback(*want, intParam);
|
||||
freeInstallManager->NotifyFreeInstallResult(*want, intParam, int64Param);
|
||||
freeInstallManager->FreeInstallAbilityFromRemote(*want, token, int32Param, intParam);
|
||||
freeInstallManager->ConnectFreeInstall(*want, int32Param, token, stringParam);
|
||||
freeInstallManager->GetTimeStamp();
|
||||
freeInstallManager->OnInstallFinished(intParam, *want, int32Param, int64Param);
|
||||
freeInstallManager->OnRemoteInstallFinished(intParam, *want, int32Param, int64Param);
|
||||
|
||||
// fuzz for AtomicServiceStatusCallback
|
||||
std::weak_ptr<FreeInstallManager> fimWeakPtr{freeInstallManager};
|
||||
auto atomicServiceStatusCallback = std::make_shared<AtomicServiceStatusCallback>(fimWeakPtr, int64Param);
|
||||
atomicServiceStatusCallback->OnInstallFinished(intParam, *want, int32Param);
|
||||
atomicServiceStatusCallback->OnRemoteInstallFinished(intParam, *want, int32Param);
|
||||
|
||||
// fuzz for AtomicServiceStatusCallbackProxy
|
||||
sptr<IRemoteObject> impl = GetFuzzAbilityToken();
|
||||
auto atomicServiceStatusCallbackProxy = std::make_shared<AtomicServiceStatusCallbackProxy>(impl);
|
||||
atomicServiceStatusCallbackProxy->OnInstallFinished(intParam, *want, int32Param);
|
||||
atomicServiceStatusCallbackProxy->OnRemoteInstallFinished(intParam, *want, int32Param);
|
||||
|
||||
// fuzz for BackgroundTaskObserver
|
||||
auto backgroundTaskObserver = std::make_shared<BackgroundTaskObserver>();
|
||||
auto continuousTaskCallbackInfo = std::make_shared<BackgroundTaskMgr::ContinuousTaskCallbackInfo>();
|
||||
backgroundTaskObserver->OnContinuousTaskStart(continuousTaskCallbackInfo);
|
||||
backgroundTaskObserver->OnContinuousTaskStop(continuousTaskCallbackInfo);
|
||||
wptr<IRemoteObject> object{token};
|
||||
|
||||
// fuzz for CallRecord
|
||||
auto callRecord = std::make_shared<CallRecord>(int32Param, targetService, connect, token);
|
||||
callRecord->CreateCallRecord(int32Param, targetService, connect, token);
|
||||
callRecord->SetCallStub(token);
|
||||
callRecord->GetCallStub();
|
||||
callRecord->SetConCallBack(connect);
|
||||
callRecord->GetConCallBack();
|
||||
callRecord->GetTargetServiceName();
|
||||
callRecord->GetCallerToken();
|
||||
callRecord->SchedulerConnectDone();
|
||||
callRecord->SchedulerDisconnectDone();
|
||||
callRecord->OnCallStubDied(object);
|
||||
callRecord->Dump(info);
|
||||
callRecord->GetCallerUid();
|
||||
CallState state = CallState::INIT;
|
||||
callRecord->IsCallState(state);
|
||||
callRecord->SetCallState(state);
|
||||
callRecord->GetCallRecordId();
|
||||
|
||||
// fuzz for CallContainer
|
||||
auto callContainer = std::make_shared<CallContainer>();
|
||||
callContainer->AddCallRecord(connect, callRecord);
|
||||
callContainer->GetCallRecord(connect);
|
||||
callContainer->RemoveCallRecord(connect);
|
||||
callContainer->OnConnectionDied(object);
|
||||
callContainer->CallRequestDone(token);
|
||||
callContainer->Dump(info);
|
||||
callContainer->IsNeedToCallRequest();
|
||||
callContainer->AddConnectDeathRecipient(connect);
|
||||
callContainer->RemoveConnectDeathRecipient(connect);
|
||||
|
||||
// fuzz for CallerInfo
|
||||
auto callerInfo = std::make_shared<CallerInfo>();
|
||||
Parcel parcel;
|
||||
callerInfo->Marshalling(parcel);
|
||||
callerInfo->Unmarshalling(parcel);
|
||||
callerInfo->ReadFromParcel(parcel);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/* Fuzzer entry point */
|
||||
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
|
||||
{
|
||||
/* Run your code on data */
|
||||
if (data == nullptr) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Validate the length of size */
|
||||
if (size < OHOS::U32_AT_SIZE || size > OHOS::FOO_MAX_LEN) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
char* ch = (char *)malloc(size + 1);
|
||||
if (ch == nullptr) {
|
||||
std::cout << "malloc failed." << std::endl;
|
||||
return 0;
|
||||
}
|
||||
|
||||
(void)memset_s(ch, size + 1, 0x00, size + 1);
|
||||
if (memcpy_s(ch, size, data, size) != EOK) {
|
||||
std::cout << "copy failed." << std::endl;
|
||||
free(ch);
|
||||
ch = nullptr;
|
||||
return 0;
|
||||
}
|
||||
|
||||
OHOS::DoSomethingInterestingWithMyAPI(ch, size);
|
||||
free(ch);
|
||||
ch = nullptr;
|
||||
return 0;
|
||||
}
|
||||
|
||||
+21
@@ -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_APPLICATIONANRLISTENER_FUZZER_H
|
||||
#define FUZZTEST_OHOS_ABILITY_RUNTIME_APPLICATIONANRLISTENER_FUZZER_H
|
||||
|
||||
#define FUZZ_PROJECT_NAME "applicationanrlistener_fuzzer"
|
||||
|
||||
#endif // FUZZTEST_OHOS_ABILITY_RUNTIME_APPLICATIONANRLISTENER_FUZZER_H
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
FUZZ
|
||||
+25
@@ -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>
|
||||
+88
@@ -0,0 +1,88 @@
|
||||
# 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")
|
||||
import("//foundation/resourceschedule/background_task_mgr/bgtaskmgr.gni")
|
||||
module_output_path = "ability_runtime/abilitymgr"
|
||||
|
||||
##############################fuzztest##########################################
|
||||
ohos_fuzztest("ConnectionStateManagerFuzzTest") {
|
||||
module_out_path = module_output_path
|
||||
|
||||
fuzz_config_file =
|
||||
"${ability_runtime_test_path}/fuzztest/connectionstatemanager_fuzzer"
|
||||
include_dirs = [
|
||||
"${ability_runtime_innerkits_path}/ability_manager/include",
|
||||
"${ability_runtime_innerkits_path}/dataobs_manager/include",
|
||||
"${bgtaskmgr_interfaces_path}/innerkits/include",
|
||||
"${multimodalinput_path}/interfaces/native/innerkits/event/include",
|
||||
]
|
||||
cflags = [
|
||||
"-g",
|
||||
"-O0",
|
||||
"-Wno-unused-variable",
|
||||
"-fno-omit-frame-pointer",
|
||||
]
|
||||
sources = [ "connectionstatemanager_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",
|
||||
"ability_runtime:connection_obs_manager",
|
||||
"bundle_framework:appexecfwk_base",
|
||||
"c_utils:utils",
|
||||
"common_event_service:cesfwk_core",
|
||||
"common_event_service:cesfwk_innerkits",
|
||||
"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
|
||||
":ConnectionStateManagerFuzzTest",
|
||||
]
|
||||
}
|
||||
###############################################################################
|
||||
+256
@@ -0,0 +1,256 @@
|
||||
/*
|
||||
* 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 "connectionstatemanager_fuzzer.h"
|
||||
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
|
||||
#define private public
|
||||
#define protected public
|
||||
#include "connection_observer_controller.h"
|
||||
#include "connection_record.h"
|
||||
#include "connection_state_item.h"
|
||||
#include "connection_state_manager.h"
|
||||
#undef protected
|
||||
#undef private
|
||||
|
||||
#include "ability_record.h"
|
||||
#include "continuous_task_callback_info.h"
|
||||
|
||||
using namespace OHOS::AAFwk;
|
||||
using namespace OHOS::AppExecFwk;
|
||||
using namespace OHOS::AbilityRuntime;
|
||||
|
||||
namespace OHOS {
|
||||
namespace {
|
||||
constexpr size_t FOO_MAX_LEN = 1024;
|
||||
constexpr size_t U32_AT_SIZE = 4;
|
||||
constexpr uint8_t ENABLE = 2;
|
||||
class MyAbilityConnection : public IAbilityConnection {
|
||||
public:
|
||||
MyAbilityConnection() = default;
|
||||
virtual ~MyAbilityConnection() = default;
|
||||
void OnAbilityConnectDone(
|
||||
const AppExecFwk::ElementName &element, const sptr<IRemoteObject> &remoteObject, int resultCode) override
|
||||
{}
|
||||
void OnAbilityDisconnectDone(const AppExecFwk::ElementName &element, int resultCode) override
|
||||
{}
|
||||
sptr<IRemoteObject> AsObject() override
|
||||
{
|
||||
return {};
|
||||
}
|
||||
};
|
||||
class MyAbilityConnectionObserver : public IConnectionObserver {
|
||||
public:
|
||||
MyAbilityConnectionObserver() = default;
|
||||
virtual ~MyAbilityConnectionObserver() = default;
|
||||
void OnExtensionConnected(const ConnectionData &data) override
|
||||
{}
|
||||
void OnExtensionDisconnected(const ConnectionData &data) override
|
||||
{}
|
||||
void OnDlpAbilityOpened(const DlpStateData &data) override
|
||||
{}
|
||||
void OnDlpAbilityClosed(const DlpStateData &data) override
|
||||
{}
|
||||
sptr<IRemoteObject> AsObject() override
|
||||
{
|
||||
return {};
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
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];
|
||||
}
|
||||
|
||||
std::shared_ptr<AbilityRecord> GetFuzzAbilityRecord()
|
||||
{
|
||||
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) {
|
||||
return nullptr;
|
||||
}
|
||||
return abilityRecord;
|
||||
}
|
||||
|
||||
sptr<Token> GetFuzzAbilityToken()
|
||||
{
|
||||
sptr<Token> token = nullptr;
|
||||
std::shared_ptr<AbilityRecord> abilityRecord = GetFuzzAbilityRecord();
|
||||
if (abilityRecord) {
|
||||
token = abilityRecord->GetToken();
|
||||
}
|
||||
return token;
|
||||
}
|
||||
|
||||
bool DoSomethingInterestingWithMyAPI(const char* data, size_t size)
|
||||
{
|
||||
bool boolParam = *data % ENABLE;
|
||||
int intParam = static_cast<int>(GetU32Data(data));
|
||||
int32_t int32Param = static_cast<int32_t>(GetU32Data(data));
|
||||
std::string stringParam(data, size);
|
||||
Parcel wantParcel;
|
||||
Want *want = nullptr;
|
||||
if (wantParcel.WriteBuffer(data, size)) {
|
||||
want = Want::Unmarshalling(wantParcel);
|
||||
if (!want) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
sptr<IRemoteObject> token = GetFuzzAbilityToken();
|
||||
sptr<IAbilityConnection> connect = new MyAbilityConnection();
|
||||
sptr<AbilityRuntime::IConnectionObserver> observer = new MyAbilityConnectionObserver();
|
||||
std::vector<std::string> info;
|
||||
AbilityRuntime::ConnectionData connectionData;
|
||||
|
||||
// fuzz for ConnectionObserverController
|
||||
auto connectionObserverController = std::make_shared<ConnectionObserverController>();
|
||||
connectionObserverController->AddObserver(observer);
|
||||
connectionObserverController->RemoveObserver(observer);
|
||||
connectionObserverController->NotifyExtensionConnected(connectionData);
|
||||
connectionObserverController->NotifyExtensionDisconnected(connectionData);
|
||||
AbilityRuntime::DlpStateData dlpStateData;
|
||||
connectionObserverController->NotifyDlpAbilityOpened(dlpStateData);
|
||||
connectionObserverController->NotifyDlpAbilityClosed(dlpStateData);
|
||||
connectionObserverController->GetObservers();
|
||||
wptr<IRemoteObject> remote;
|
||||
connectionObserverController->HandleRemoteDied(remote);
|
||||
ConnectionObserverController::ObserverDeathRecipient::ObserverDeathHandler handler;
|
||||
auto observerDeathRecipient =
|
||||
new ConnectionObserverController::ObserverDeathRecipient(handler);
|
||||
observerDeathRecipient->OnRemoteDied(remote);
|
||||
|
||||
// fuzz for ConnectionRecord
|
||||
std::shared_ptr<AbilityRecord> targetService = GetFuzzAbilityRecord();
|
||||
auto connectionRecord = std::make_shared<ConnectionRecord>(token, targetService, connect);
|
||||
connectionRecord->CreateConnectionRecord(token, targetService, connect);
|
||||
ConnectionState state = ConnectionState::CONNECTED;
|
||||
connectionRecord->SetConnectState(state);
|
||||
connectionRecord->GetConnectState();
|
||||
connectionRecord->GetToken();
|
||||
connectionRecord->GetAbilityRecord();
|
||||
connectionRecord->GetAbilityConnectCallback();
|
||||
connectionRecord->ClearConnCallBack();
|
||||
connectionRecord->DisconnectAbility();
|
||||
connectionRecord->CompleteConnect(intParam);
|
||||
connectionRecord->CompleteDisconnect(intParam, boolParam);
|
||||
connectionRecord->ScheduleDisconnectAbilityDone();
|
||||
connectionRecord->ScheduleConnectAbilityDone();
|
||||
connectionRecord->DisconnectTimeout();
|
||||
connectionRecord->ConvertConnectionState(state);
|
||||
connectionRecord->Dump(info);
|
||||
connectionRecord->AttachCallerInfo();
|
||||
connectionRecord->GetCallerUid();
|
||||
connectionRecord->GetCallerPid();
|
||||
connectionRecord->GetCallerName();
|
||||
connectionRecord->GetTargetToken();
|
||||
connectionRecord->GetConnection();
|
||||
|
||||
// fuzz for ConnectionRecord
|
||||
auto connectionStateItem = std::make_shared<ConnectionStateItem>(int32Param, int32Param, stringParam);
|
||||
std::shared_ptr<ConnectionRecord> record;
|
||||
connectionStateItem->CreateConnectionStateItem(record);
|
||||
DataAbilityCaller dataCaller;
|
||||
connectionStateItem->CreateConnectionStateItem(dataCaller);
|
||||
connectionStateItem->AddConnection(record, connectionData);
|
||||
connectionStateItem->RemoveConnection(record, connectionData);
|
||||
std::shared_ptr<DataAbilityRecord> dataAbility;
|
||||
connectionStateItem->AddDataAbilityConnection(dataCaller, dataAbility, connectionData);
|
||||
connectionStateItem->RemoveDataAbilityConnection(dataCaller, dataAbility, connectionData);
|
||||
connectionStateItem->HandleDataAbilityDied(token, connectionData);
|
||||
connectionStateItem->IsEmpty();
|
||||
std::vector<AbilityRuntime::ConnectionData> datas;
|
||||
connectionStateItem->GenerateAllConnectionData(datas);
|
||||
std::shared_ptr<ConnectedExtension> connectedExtension;
|
||||
connectionStateItem->GenerateConnectionData(connectedExtension, connectionData);
|
||||
std::shared_ptr<ConnectedDataAbility> connectedDataAbility;
|
||||
connectionStateItem->GenerateConnectionData(connectedDataAbility, connectionData);
|
||||
|
||||
// fuzz for ConnectionStateManager
|
||||
auto connectionStateManager = std::make_shared<ConnectionStateManager>();
|
||||
connectionStateManager->GetProcessNameByPid(int32Param);
|
||||
connectionStateManager->Init();
|
||||
connectionStateManager->RegisterObserver(observer);
|
||||
connectionStateManager->UnregisterObserver(observer);
|
||||
connectionStateManager->AddConnection(record);
|
||||
connectionStateManager->RemoveConnection(record, boolParam);
|
||||
connectionStateManager->AddDataAbilityConnection(dataCaller, dataAbility);
|
||||
connectionStateManager->RemoveDataAbilityConnection(dataCaller, dataAbility);
|
||||
connectionStateManager->CheckDataAbilityConnectionParams(dataCaller, dataAbility);
|
||||
connectionStateManager->HandleDataAbilityDied(dataAbility);
|
||||
connectionStateManager->HandleDataAbilityCallerDied(int32Param);
|
||||
std::shared_ptr<AbilityRecord> dlpManger = GetFuzzAbilityRecord();
|
||||
connectionStateManager->AddDlpManager(dlpManger);
|
||||
connectionStateManager->RemoveDlpManager(dlpManger);
|
||||
connectionStateManager->AddDlpAbility(dlpManger);
|
||||
connectionStateManager->RemoveDlpAbility(dlpManger);
|
||||
connectionStateManager->HandleAppDied(int32Param);
|
||||
std::vector<AbilityRuntime::DlpConnectionInfo> infos;
|
||||
connectionStateManager->GetDlpConnectionInfos(infos);
|
||||
connectionStateManager->AddConnectionInner(connectionRecord, connectionData);
|
||||
connectionStateManager->RemoveConnectionInner(connectionRecord, connectionData);
|
||||
connectionStateManager->HandleCallerDied(int32Param);
|
||||
connectionStateManager->RemoveDiedCaller(int32Param);
|
||||
connectionStateManager->AddDataAbilityConnectionInner(dataCaller, dataAbility, connectionData);
|
||||
connectionStateManager->RemoveDataAbilityConnectionInner(dataCaller, dataAbility, connectionData);
|
||||
connectionStateManager->HandleDataAbilityDiedInner(token, datas);
|
||||
AbilityRuntime::DlpStateData dlpData;
|
||||
connectionStateManager->HandleDlpAbilityInner(dlpManger, boolParam, dlpData);
|
||||
connectionStateManager->InitAppStateObserver();
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/* Fuzzer entry point */
|
||||
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
|
||||
{
|
||||
/* Run your code on data */
|
||||
if (data == nullptr) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Validate the length of size */
|
||||
if (size < OHOS::U32_AT_SIZE || size > OHOS::FOO_MAX_LEN) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
char* ch = (char *)malloc(size + 1);
|
||||
if (ch == nullptr) {
|
||||
std::cout << "malloc failed." << std::endl;
|
||||
return 0;
|
||||
}
|
||||
|
||||
(void)memset_s(ch, size + 1, 0x00, size + 1);
|
||||
if (memcpy_s(ch, size, data, size) != EOK) {
|
||||
std::cout << "copy failed." << std::endl;
|
||||
free(ch);
|
||||
ch = nullptr;
|
||||
return 0;
|
||||
}
|
||||
|
||||
OHOS::DoSomethingInterestingWithMyAPI(ch, size);
|
||||
free(ch);
|
||||
ch = nullptr;
|
||||
return 0;
|
||||
}
|
||||
|
||||
+21
@@ -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_CONNECTIONSTATEMANAGER_FUZZER_H
|
||||
#define FUZZTEST_OHOS_ABILITY_RUNTIME_CONNECTIONSTATEMANAGER_FUZZER_H
|
||||
|
||||
#define FUZZ_PROJECT_NAME "connectionstatemanager_fuzzer"
|
||||
|
||||
#endif // FUZZTEST_OHOS_ABILITY_RUNTIME_CONNECTIONSTATEMANAGER_FUZZER_H
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
FUZZ
|
||||
+25
@@ -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>
|
||||
Reference in New Issue
Block a user