mirror of
https://gitee.com/openharmony/ability_dmsfwk
synced 2024-12-03 11:51:05 +00:00
add fuzz
Signed-off-by: shihaojie6128 <shihaojie10@huawei.com>
This commit is contained in:
parent
595a4a65b5
commit
d4cacbd5ed
@ -135,7 +135,7 @@
|
||||
"//foundation/ability/dmsfwk/interfaces/innerkits/tests:dms_sdk_demo",
|
||||
"//foundation/ability/dmsfwk/services/dtbschedmgr:unittest",
|
||||
"//foundation/ability/dmsfwk/services/dtbabilitymgr:unittest",
|
||||
"//foundation/ability/dmsfwk/test/fuzztest/continuationmanager_fuzzer:fuzztest"
|
||||
"//foundation/ability/dmsfwk/test/fuzztest:fuzztest"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
@ -94,13 +94,6 @@ public:
|
||||
virtual int32_t DisconnectAbilityFromRemote(const sptr<IRemoteObject>& connect,
|
||||
int32_t uid, const std::string& sourceDeviceId) = 0;
|
||||
virtual int32_t NotifyProcessDiedFromRemote(const CallerInfo& callerInfo) = 0;
|
||||
#ifdef SUPPORT_DISTRIBUTED_MISSION_MANAGER
|
||||
virtual int32_t StartSyncRemoteMissions(const std::string& devId, bool fixConflict, int64_t tag) = 0;
|
||||
virtual int32_t StartSyncMissionsFromRemote(const CallerInfo& callerInfo,
|
||||
std::vector<DstbMissionInfo>& missionInfos) = 0;
|
||||
virtual int32_t StopSyncRemoteMissions(const std::string& devId) = 0;
|
||||
virtual int32_t StopSyncMissionsFromRemote(const CallerInfo& callerInfo) = 0;
|
||||
virtual int32_t RegisterMissionListener(const std::u16string& devId, const sptr<IRemoteObject>& obj) = 0;
|
||||
virtual int32_t RegisterDSchedEventListener(const DSchedEventType& type, const sptr<IRemoteObject>& obj)
|
||||
{
|
||||
return 0;
|
||||
@ -117,6 +110,13 @@ public:
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
#ifdef SUPPORT_DISTRIBUTED_MISSION_MANAGER
|
||||
virtual int32_t StartSyncRemoteMissions(const std::string& devId, bool fixConflict, int64_t tag) = 0;
|
||||
virtual int32_t StartSyncMissionsFromRemote(const CallerInfo& callerInfo,
|
||||
std::vector<DstbMissionInfo>& missionInfos) = 0;
|
||||
virtual int32_t StopSyncRemoteMissions(const std::string& devId) = 0;
|
||||
virtual int32_t StopSyncMissionsFromRemote(const CallerInfo& callerInfo) = 0;
|
||||
virtual int32_t RegisterMissionListener(const std::u16string& devId, const sptr<IRemoteObject>& obj) = 0;
|
||||
virtual int32_t RegisterOnListener(const std::string& type, const sptr<IRemoteObject>& obj)
|
||||
{
|
||||
return 0;
|
||||
|
21
test/fuzztest/BUILD.gn
Normal file
21
test/fuzztest/BUILD.gn
Normal file
@ -0,0 +1,21 @@
|
||||
# Copyright (c) 2024 Huawei Device Co., Ltd.
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
group("fuzztest") {
|
||||
testonly = true
|
||||
|
||||
deps = [
|
||||
"continuationmanager_fuzzer:fuzztest",
|
||||
"distributedschedstub_fuzzer:fuzztest",
|
||||
]
|
||||
}
|
89
test/fuzztest/distributedschedstub_fuzzer/BUILD.gn
Normal file
89
test/fuzztest/distributedschedstub_fuzzer/BUILD.gn
Normal file
@ -0,0 +1,89 @@
|
||||
# Copyright (c) 2022-2024 Huawei Device Co., Ltd.
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
#####################hydra-fuzz###################
|
||||
import("//build/config/features.gni")
|
||||
import("//build/ohos.gni")
|
||||
import("//build/test.gni")
|
||||
import("//foundation/ability/dmsfwk/dmsfwk.gni")
|
||||
ohos_fuzztest("DistributedSchedStubFuzzTest") {
|
||||
module_out_path = module_output_path
|
||||
|
||||
visibility = [ ":*" ]
|
||||
include_dirs = [
|
||||
"${dms_path}/test/fuzztest/distributedschedstub_fuzzer",
|
||||
"${dms_path}/services/dtbschedmgr/include/",
|
||||
"${dms_path}/interfaces/innerkits/common/include/",
|
||||
"${dms_path}/services/dtbschedmgr/include/collaborate/",
|
||||
"${dms_path}/common/include/",
|
||||
]
|
||||
|
||||
fuzz_config_file = "${dms_path}/test/fuzztest/distributedschedstub_fuzzer"
|
||||
|
||||
configs = [ "${dms_path}/services/dtbschedmgr/test/resource:coverage_flags" ]
|
||||
|
||||
cflags = [
|
||||
"-g",
|
||||
"-O0",
|
||||
"-Wno-unused-variable",
|
||||
"-fno-omit-frame-pointer",
|
||||
"-Dprivate=public",
|
||||
]
|
||||
|
||||
sources = [
|
||||
"distributedschedstub_fuzzer.cpp",
|
||||
"fuzz_util.cpp",
|
||||
]
|
||||
|
||||
deps = [ "${dms_path}/services/dtbschedmgr:distributedschedsvr" ]
|
||||
|
||||
external_deps = [
|
||||
"ability_base:base",
|
||||
"ability_base:want",
|
||||
"ability_base:zuri",
|
||||
"ability_runtime:ability_manager",
|
||||
"ability_runtime:app_manager",
|
||||
"ability_runtime:dataobs_manager",
|
||||
"ability_runtime:mission_info",
|
||||
"access_token:libaccesstoken_sdk",
|
||||
"access_token:libnativetoken",
|
||||
"access_token:libtoken_setproc",
|
||||
"bundle_framework:appexecfwk_base",
|
||||
"bundle_framework:appexecfwk_core",
|
||||
"cJSON:cjson",
|
||||
"c_utils:utils",
|
||||
"data_share:datashare_consumer",
|
||||
"device_auth:deviceauth_sdk",
|
||||
"device_info_manager:distributed_device_profile_common",
|
||||
"device_info_manager:distributed_device_profile_sdk",
|
||||
"device_manager:devicemanagersdk",
|
||||
"device_security_level:dslm_sdk",
|
||||
"distributed_bundle_framework:dbms_fwk",
|
||||
"dsoftbus:softbus_client",
|
||||
"eventhandler:libeventhandler",
|
||||
"hilog:libhilog",
|
||||
"hisysevent:libhisysevent",
|
||||
"hitrace:hitrace_meter",
|
||||
"hitrace:libhitracechain",
|
||||
"init:libbegetutil",
|
||||
"ipc:ipc_core",
|
||||
"kv_store:distributeddata_inner",
|
||||
"safwk:system_ability_fwk",
|
||||
"samgr:samgr_proxy",
|
||||
]
|
||||
}
|
||||
|
||||
group("fuzztest") {
|
||||
testonly = true
|
||||
deps = [ ":DistributedSchedStubFuzzTest" ]
|
||||
}
|
16
test/fuzztest/distributedschedstub_fuzzer/corpus/init
Normal file
16
test/fuzztest/distributedschedstub_fuzzer/corpus/init
Normal file
@ -0,0 +1,16 @@
|
||||
/*
|
||||
* Copyright (c) 2024 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
FUZZ
|
@ -0,0 +1,470 @@
|
||||
/*
|
||||
* Copyright (c) 2022-2024 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "distributedschedstub_fuzzer.h"
|
||||
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <singleton.h>
|
||||
|
||||
#include "distributed_sched_interface.h"
|
||||
#include "distributed_sched_service.h"
|
||||
#include "distributed_sched_stub.h"
|
||||
#include "fuzz_util.h"
|
||||
#include "parcel_helper.h"
|
||||
|
||||
using namespace OHOS::AAFwk;
|
||||
using namespace OHOS::AppExecFwk;
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedSchedule {
|
||||
namespace {
|
||||
const std::u16string DMS_STUB_INTERFACE_TOKEN = u"ohos.distributedschedule.accessToken";
|
||||
}
|
||||
|
||||
bool StartRemoteAbilityInnerFuzzTest(const uint8_t* data, size_t size)
|
||||
{
|
||||
if ((data == nullptr) || (size < sizeof(int32_t))) {
|
||||
return false;
|
||||
}
|
||||
FuzzUtil::MockPermission();
|
||||
int32_t code = static_cast<uint32_t>(IDSchedInterfaceCode::START_REMOTE_ABILITY);
|
||||
MessageParcel dataParcel;
|
||||
MessageParcel reply;
|
||||
MessageOption option;
|
||||
Want want;
|
||||
int32_t callerUid = *(reinterpret_cast<const int32_t*>(data));
|
||||
int32_t requestCode = *(reinterpret_cast<const int32_t*>(data));
|
||||
uint32_t accessToken = *(reinterpret_cast<const uint32_t*>(data));
|
||||
dataParcel.WriteInterfaceToken(DMS_STUB_INTERFACE_TOKEN);
|
||||
dataParcel.WriteParcelable(&want);
|
||||
dataParcel.WriteInt32(callerUid);
|
||||
dataParcel.WriteInt32(requestCode);
|
||||
dataParcel.WriteUint32(accessToken);
|
||||
DelayedSingleton<DistributedSchedService>::GetInstance()->OnRemoteRequest(code, dataParcel, reply, option);
|
||||
return true;
|
||||
}
|
||||
|
||||
void ConnectRemoteAbilityInnerFuzzTest(const uint8_t* data, size_t size)
|
||||
{
|
||||
if ((data == nullptr) || (size < sizeof(int32_t))) {
|
||||
return;
|
||||
}
|
||||
FuzzUtil::MockPermission();
|
||||
int32_t code = static_cast<uint32_t>(IDSchedInterfaceCode::CONNECT_REMOTE_ABILITY);
|
||||
MessageParcel dataParcel;
|
||||
MessageParcel reply;
|
||||
MessageOption option;
|
||||
Want want;
|
||||
int32_t callerUid = *(reinterpret_cast<const int32_t*>(data));
|
||||
int32_t callerPid = *(reinterpret_cast<const int32_t*>(data));
|
||||
uint32_t accessToken = *(reinterpret_cast<const int32_t*>(data));
|
||||
dataParcel.WriteInterfaceToken(DMS_STUB_INTERFACE_TOKEN);
|
||||
dataParcel.WriteParcelable(&want);
|
||||
dataParcel.WriteInt32(callerUid);
|
||||
dataParcel.WriteInt32(callerPid);
|
||||
dataParcel.WriteUint32(accessToken);
|
||||
DelayedSingleton<DistributedSchedService>::GetInstance()->OnRemoteRequest(code, dataParcel, reply, option);
|
||||
}
|
||||
|
||||
void DisconnectRemoteAbilityInnerFuzzTest(const uint8_t* data, size_t size)
|
||||
{
|
||||
if ((data == nullptr) || (size < sizeof(int32_t))) {
|
||||
return;
|
||||
}
|
||||
FuzzUtil::MockPermission();
|
||||
int32_t code = static_cast<uint32_t>(IDSchedInterfaceCode::DISCONNECT_REMOTE_ABILITY);
|
||||
MessageParcel dataParcel;
|
||||
MessageParcel reply;
|
||||
MessageOption option;
|
||||
int32_t callerUid = *(reinterpret_cast<const int32_t*>(data));
|
||||
uint32_t accessToken = *(reinterpret_cast<const int32_t*>(data));
|
||||
dataParcel.WriteInterfaceToken(DMS_STUB_INTERFACE_TOKEN);
|
||||
dataParcel.WriteInt32(callerUid);
|
||||
dataParcel.WriteUint32(accessToken);
|
||||
DelayedSingleton<DistributedSchedService>::GetInstance()->OnRemoteRequest(code, dataParcel, reply, option);
|
||||
}
|
||||
|
||||
void StartContinuationInnerFuzzTest(const uint8_t* data, size_t size)
|
||||
{
|
||||
if ((data == nullptr) || (size < sizeof(int32_t))) {
|
||||
return;
|
||||
}
|
||||
FuzzUtil::MockPermission();
|
||||
int32_t code = static_cast<uint32_t>(IDSchedInterfaceCode::START_CONTINUATION);
|
||||
MessageParcel dataParcel;
|
||||
MessageParcel reply;
|
||||
MessageOption option;
|
||||
Want want;
|
||||
int32_t missionId = *(reinterpret_cast<const int32_t*>(data));
|
||||
int32_t callerUid = *(reinterpret_cast<const int32_t*>(data));
|
||||
int32_t status = *(reinterpret_cast<const int32_t*>(data));
|
||||
uint32_t accessToken = *(reinterpret_cast<const int32_t*>(data));
|
||||
dataParcel.WriteInterfaceToken(DMS_STUB_INTERFACE_TOKEN);
|
||||
dataParcel.WriteParcelable(&want);
|
||||
dataParcel.WriteInt32(missionId);
|
||||
dataParcel.WriteInt32(callerUid);
|
||||
dataParcel.WriteInt32(status);
|
||||
dataParcel.WriteUint32(accessToken);
|
||||
DelayedSingleton<DistributedSchedService>::GetInstance()->OnRemoteRequest(code, dataParcel, reply, option);
|
||||
}
|
||||
|
||||
void NotifyCompleteContinuationInnerFuzzTest(const uint8_t* data, size_t size)
|
||||
{
|
||||
if ((data == nullptr) || (size < sizeof(int32_t))) {
|
||||
return;
|
||||
}
|
||||
FuzzUtil::MockPermission();
|
||||
int32_t code = static_cast<uint32_t>(IDSchedInterfaceCode::NOTIFY_COMPLETE_CONTINUATION);
|
||||
MessageParcel dataParcel;
|
||||
MessageParcel reply;
|
||||
MessageOption option;
|
||||
int32_t sessionId = *(reinterpret_cast<const int32_t*>(data));
|
||||
dataParcel.WriteInterfaceToken(DMS_STUB_INTERFACE_TOKEN);
|
||||
dataParcel.WriteInt32(sessionId);
|
||||
DelayedSingleton<DistributedSchedService>::GetInstance()->OnRemoteRequest(code, dataParcel, reply, option);
|
||||
}
|
||||
|
||||
void ContinueMissionInnerFuzzTest(const uint8_t* data, size_t size)
|
||||
{
|
||||
if ((data == nullptr) || (size < sizeof(int32_t))) {
|
||||
return;
|
||||
}
|
||||
FuzzUtil::MockPermission();
|
||||
MessageParcel dataParcel;
|
||||
MessageParcel reply;
|
||||
std::string srcDevId(reinterpret_cast<const char*>(data), size);
|
||||
std::string dstDevId(reinterpret_cast<const char*>(data), size);
|
||||
int32_t missionId = *(reinterpret_cast<const int32_t*>(data));
|
||||
dataParcel.WriteString(srcDevId);
|
||||
dataParcel.WriteString(dstDevId);
|
||||
dataParcel.WriteInt32(missionId);
|
||||
DelayedSingleton<DistributedSchedService>::GetInstance()->ContinueMissionInner(dataParcel, reply);
|
||||
}
|
||||
|
||||
void ContinueMissionOfBundleNameInnerFuzzTest(const uint8_t* data, size_t size)
|
||||
{
|
||||
if ((data == nullptr) || (size < sizeof(int32_t))) {
|
||||
return;
|
||||
}
|
||||
FuzzUtil::MockPermission();
|
||||
MessageParcel dataParcel;
|
||||
MessageParcel reply;
|
||||
std::string srcDevId(reinterpret_cast<const char*>(data), size);
|
||||
std::string dstDevId(reinterpret_cast<const char*>(data), size);
|
||||
std::string bundleName(reinterpret_cast<const char*>(data), size);
|
||||
dataParcel.WriteString(srcDevId);
|
||||
dataParcel.WriteString(dstDevId);
|
||||
dataParcel.WriteString(bundleName);
|
||||
DelayedSingleton<DistributedSchedService>::GetInstance()->ContinueMissionOfBundleNameInner(dataParcel, reply);
|
||||
}
|
||||
|
||||
void GetMissionInfosInnerFuzzTest(const uint8_t* data, size_t size)
|
||||
{
|
||||
if ((data == nullptr) || (size < sizeof(int32_t))) {
|
||||
return;
|
||||
}
|
||||
FuzzUtil::MockPermission();
|
||||
int32_t code = static_cast<uint32_t>(IDSchedInterfaceCode::GET_MISSION_INFOS);
|
||||
MessageParcel dataParcel;
|
||||
MessageParcel reply;
|
||||
MessageOption option;
|
||||
int32_t numMissions = *(reinterpret_cast<const int32_t*>(data));
|
||||
dataParcel.WriteInterfaceToken(DMS_STUB_INTERFACE_TOKEN);
|
||||
dataParcel.WriteInt32(numMissions);
|
||||
DelayedSingleton<DistributedSchedService>::GetInstance()->OnRemoteRequest(code, dataParcel, reply, option);
|
||||
}
|
||||
|
||||
void RegisterMissionListenerInnerFuzzTest(const uint8_t* data, size_t size)
|
||||
{
|
||||
if ((data == nullptr) || (size < sizeof(int32_t))) {
|
||||
return;
|
||||
}
|
||||
FuzzUtil::MockPermission();
|
||||
int32_t code = static_cast<uint32_t>(IDSchedInterfaceCode::REGISTER_MISSION_LISTENER);
|
||||
MessageParcel dataParcel;
|
||||
MessageParcel reply;
|
||||
MessageOption option;
|
||||
dataParcel.WriteInterfaceToken(DMS_STUB_INTERFACE_TOKEN);
|
||||
DelayedSingleton<DistributedSchedService>::GetInstance()->OnRemoteRequest(code, dataParcel, reply, option);
|
||||
}
|
||||
|
||||
void UnRegisterMissionListenerInnerFuzzTest(const uint8_t* data, size_t size)
|
||||
{
|
||||
if ((data == nullptr) || (size < sizeof(int32_t))) {
|
||||
return;
|
||||
}
|
||||
FuzzUtil::MockPermission();
|
||||
int32_t code = static_cast<uint32_t>(IDSchedInterfaceCode::UNREGISTER_MISSION_LISTENER);
|
||||
MessageParcel dataParcel;
|
||||
MessageParcel reply;
|
||||
MessageOption option;
|
||||
dataParcel.WriteInterfaceToken(DMS_STUB_INTERFACE_TOKEN);
|
||||
DelayedSingleton<DistributedSchedService>::GetInstance()->OnRemoteRequest(code, dataParcel, reply, option);
|
||||
}
|
||||
|
||||
void StartSyncRemoteMissionsInnerFuzzTest(const uint8_t* data, size_t size)
|
||||
{
|
||||
if ((data == nullptr) || (size < sizeof(int32_t))) {
|
||||
return;
|
||||
}
|
||||
FuzzUtil::MockPermission();
|
||||
int32_t code = static_cast<uint32_t>(IDSchedInterfaceCode::START_SYNC_MISSIONS);
|
||||
MessageParcel dataParcel;
|
||||
MessageParcel reply;
|
||||
MessageOption option;
|
||||
dataParcel.WriteInterfaceToken(DMS_STUB_INTERFACE_TOKEN);
|
||||
DelayedSingleton<DistributedSchedService>::GetInstance()->OnRemoteRequest(code, dataParcel, reply, option);
|
||||
}
|
||||
|
||||
void StopSyncRemoteMissionsInnerFuzzTest(const uint8_t* data, size_t size)
|
||||
{
|
||||
if ((data == nullptr) || (size < sizeof(int32_t))) {
|
||||
return;
|
||||
}
|
||||
FuzzUtil::MockPermission();
|
||||
int32_t code = static_cast<uint32_t>(IDSchedInterfaceCode::STOP_SYNC_MISSIONS);
|
||||
MessageParcel dataParcel;
|
||||
MessageParcel reply;
|
||||
MessageOption option;
|
||||
dataParcel.WriteInterfaceToken(DMS_STUB_INTERFACE_TOKEN);
|
||||
DelayedSingleton<DistributedSchedService>::GetInstance()->OnRemoteRequest(code, dataParcel, reply, option);
|
||||
}
|
||||
|
||||
void GetRemoteMissionSnapshotInfoInnerFuzzTest(const uint8_t* data, size_t size)
|
||||
{
|
||||
if ((data == nullptr) || (size < sizeof(int32_t))) {
|
||||
return;
|
||||
}
|
||||
FuzzUtil::MockPermission();
|
||||
int32_t code = static_cast<uint32_t>(IDSchedInterfaceCode::GET_REMOTE_MISSION_SNAPSHOT_INFO);
|
||||
MessageParcel dataParcel;
|
||||
MessageParcel reply;
|
||||
MessageOption option;
|
||||
std::string networkId(reinterpret_cast<const char*>(data), size);
|
||||
int32_t missionId = *(reinterpret_cast<const int32_t*>(data));
|
||||
dataParcel.WriteInterfaceToken(DMS_STUB_INTERFACE_TOKEN);
|
||||
dataParcel.WriteString(networkId);
|
||||
dataParcel.WriteInt32(missionId);
|
||||
DelayedSingleton<DistributedSchedService>::GetInstance()->OnRemoteRequest(code, dataParcel, reply, option);
|
||||
}
|
||||
|
||||
void StartRemoteAbilityByCallInnerFuzzTest(const uint8_t* data, size_t size)
|
||||
{
|
||||
if ((data == nullptr) || (size < sizeof(int32_t))) {
|
||||
return;
|
||||
}
|
||||
FuzzUtil::MockPermission();
|
||||
int32_t code = static_cast<uint32_t>(IDSchedInterfaceCode::START_REMOTE_ABILITY_BY_CALL);
|
||||
MessageParcel dataParcel;
|
||||
MessageParcel reply;
|
||||
MessageOption option;
|
||||
std::string networkId(reinterpret_cast<const char*>(data), size);
|
||||
int32_t missionId = *(reinterpret_cast<const int32_t*>(data));
|
||||
dataParcel.WriteInterfaceToken(DMS_STUB_INTERFACE_TOKEN);
|
||||
dataParcel.WriteString(networkId);
|
||||
dataParcel.WriteInt32(missionId);
|
||||
DelayedSingleton<DistributedSchedService>::GetInstance()->OnRemoteRequest(code, dataParcel, reply, option);
|
||||
}
|
||||
|
||||
void ReleaseRemoteAbilityInnerFuzzTest(const uint8_t* data, size_t size)
|
||||
{
|
||||
if ((data == nullptr) || (size < sizeof(int32_t))) {
|
||||
return;
|
||||
}
|
||||
FuzzUtil::MockPermission();
|
||||
int32_t code = static_cast<uint32_t>(IDSchedInterfaceCode::RELEASE_REMOTE_ABILITY);
|
||||
MessageParcel dataParcel;
|
||||
MessageParcel reply;
|
||||
MessageOption option;
|
||||
dataParcel.WriteInterfaceToken(DMS_STUB_INTERFACE_TOKEN);
|
||||
DelayedSingleton<DistributedSchedService>::GetInstance()->OnRemoteRequest(code, dataParcel, reply, option);
|
||||
}
|
||||
|
||||
void GetDistributedComponentListInnerFuzzTest(const uint8_t* data, size_t size)
|
||||
{
|
||||
if ((data == nullptr) || (size < sizeof(int32_t))) {
|
||||
return;
|
||||
}
|
||||
FuzzUtil::MockPermission();
|
||||
MessageParcel dataParcel;
|
||||
MessageParcel reply;
|
||||
DelayedSingleton<DistributedSchedService>::GetInstance()->GetDistributedComponentListInner(dataParcel, reply);
|
||||
}
|
||||
|
||||
void StartRemoteFreeInstallInnerFuzzTest(const uint8_t* data, size_t size)
|
||||
{
|
||||
if ((data == nullptr) || (size < sizeof(int32_t))) {
|
||||
return;
|
||||
}
|
||||
FuzzUtil::MockPermission();
|
||||
int32_t code = static_cast<uint32_t>(IDSchedInterfaceCode::START_REMOTE_FREE_INSTALL);
|
||||
MessageParcel dataParcel;
|
||||
MessageParcel reply;
|
||||
MessageOption option;
|
||||
int32_t callerUid = *(reinterpret_cast<const int32_t*>(data));
|
||||
int32_t requestCode = *(reinterpret_cast<const int32_t*>(data));
|
||||
uint32_t accessToken = *(reinterpret_cast<const int32_t*>(data));
|
||||
dataParcel.WriteInterfaceToken(DMS_STUB_INTERFACE_TOKEN);
|
||||
dataParcel.WriteInt32(callerUid);
|
||||
dataParcel.WriteInt32(requestCode);
|
||||
dataParcel.WriteUint32(accessToken);
|
||||
DelayedSingleton<DistributedSchedService>::GetInstance()->OnRemoteRequest(code, dataParcel, reply, option);
|
||||
}
|
||||
|
||||
void StartRemoteShareFormInnerFuzzTest(const uint8_t* data, size_t size)
|
||||
{
|
||||
if ((data == nullptr) || (size < sizeof(int32_t))) {
|
||||
return;
|
||||
}
|
||||
FuzzUtil::MockPermission();
|
||||
int32_t code = static_cast<uint32_t>(IDSchedInterfaceCode::START_REMOTE_SHARE_FORM);
|
||||
MessageParcel dataParcel;
|
||||
MessageParcel reply;
|
||||
MessageOption option;
|
||||
std::string deviceId(reinterpret_cast<const char*>(data), size);
|
||||
dataParcel.WriteInterfaceToken(DMS_STUB_INTERFACE_TOKEN);
|
||||
dataParcel.WriteString(deviceId);
|
||||
DelayedSingleton<DistributedSchedService>::GetInstance()->OnRemoteRequest(code, dataParcel, reply, option);
|
||||
}
|
||||
|
||||
void StopRemoteExtensionAbilityInnerFuzzTest(const uint8_t* data, size_t size)
|
||||
{
|
||||
if ((data == nullptr) || (size < sizeof(int32_t))) {
|
||||
return;
|
||||
}
|
||||
FuzzUtil::MockPermission();
|
||||
MessageParcel dataParcel;
|
||||
MessageParcel reply;
|
||||
Want want;
|
||||
int32_t callerUid = *(reinterpret_cast<const int32_t*>(data));
|
||||
int32_t serviceType = *(reinterpret_cast<const int32_t*>(data));
|
||||
uint32_t accessToken = *(reinterpret_cast<const int32_t*>(data));
|
||||
dataParcel.WriteParcelable(&want);
|
||||
dataParcel.WriteInt32(callerUid);
|
||||
dataParcel.WriteInt32(serviceType);
|
||||
dataParcel.WriteUint32(accessToken);
|
||||
DelayedSingleton<DistributedSchedService>::GetInstance()->StopRemoteExtensionAbilityInner(dataParcel, reply);
|
||||
}
|
||||
|
||||
void RegisterOnListenerInnerFuzzTest(const uint8_t* data, size_t size)
|
||||
{
|
||||
if ((data == nullptr) || (size < sizeof(int32_t))) {
|
||||
return;
|
||||
}
|
||||
FuzzUtil::MockPermission();
|
||||
int32_t code = static_cast<uint32_t>(IDSchedInterfaceCode::REGISTER_ON_LISTENER);
|
||||
MessageParcel dataParcel;
|
||||
MessageParcel reply;
|
||||
MessageOption option;
|
||||
std::string type(reinterpret_cast<const char*>(data), size);
|
||||
dataParcel.WriteInterfaceToken(DMS_STUB_INTERFACE_TOKEN);
|
||||
dataParcel.WriteString(type);
|
||||
DelayedSingleton<DistributedSchedService>::GetInstance()->OnRemoteRequest(code, dataParcel, reply, option);
|
||||
}
|
||||
|
||||
void RegisterOffListenerInnerFuzzTest(const uint8_t* data, size_t size)
|
||||
{
|
||||
if ((data == nullptr) || (size < sizeof(int32_t))) {
|
||||
return;
|
||||
}
|
||||
FuzzUtil::MockPermission();
|
||||
int32_t code = static_cast<uint32_t>(IDSchedInterfaceCode::REGISTER_OFF_LISTENER);
|
||||
MessageParcel dataParcel;
|
||||
MessageParcel reply;
|
||||
MessageOption option;
|
||||
std::string type(reinterpret_cast<const char*>(data), size);
|
||||
dataParcel.WriteInterfaceToken(DMS_STUB_INTERFACE_TOKEN);
|
||||
dataParcel.WriteString(type);
|
||||
DelayedSingleton<DistributedSchedService>::GetInstance()->OnRemoteRequest(code, dataParcel, reply, option);
|
||||
}
|
||||
|
||||
void RegisterDSchedEventListenerInnerFuzzTest(const uint8_t* data, size_t size)
|
||||
{
|
||||
if ((data == nullptr) || (size < sizeof(int32_t))) {
|
||||
return;
|
||||
}
|
||||
FuzzUtil::MockPermission();
|
||||
int32_t code = static_cast<uint32_t>(IDSchedInterfaceCode::REGISTER_DSCHED_EVENT_LISTENER);
|
||||
MessageParcel dataParcel;
|
||||
MessageParcel reply;
|
||||
MessageOption option;
|
||||
dataParcel.WriteInterfaceToken(DMS_STUB_INTERFACE_TOKEN);
|
||||
DelayedSingleton<DistributedSchedService>::GetInstance()->OnRemoteRequest(code, dataParcel, reply, option);
|
||||
}
|
||||
|
||||
void UnRegisterDSchedEventListenerInnerFuzzTest(const uint8_t* data, size_t size)
|
||||
{
|
||||
if ((data == nullptr) || (size < sizeof(int32_t))) {
|
||||
return;
|
||||
}
|
||||
FuzzUtil::MockPermission();
|
||||
int32_t code = static_cast<uint32_t>(IDSchedInterfaceCode::UNREGISTER_DSCHED_EVENT_LISTENER);
|
||||
MessageParcel dataParcel;
|
||||
MessageParcel reply;
|
||||
MessageOption option;
|
||||
dataParcel.WriteInterfaceToken(DMS_STUB_INTERFACE_TOKEN);
|
||||
DelayedSingleton<DistributedSchedService>::GetInstance()->OnRemoteRequest(code, dataParcel, reply, option);
|
||||
}
|
||||
|
||||
void SetMissionContinueStateInnerFuzzTest(const uint8_t* data, size_t size)
|
||||
{
|
||||
if ((data == nullptr) || (size < sizeof(int32_t))) {
|
||||
return;
|
||||
}
|
||||
FuzzUtil::MockPermission();
|
||||
int32_t code = static_cast<uint32_t>(IDSchedInterfaceCode::SET_MISSION_CONTINUE_STATE);
|
||||
MessageParcel dataParcel;
|
||||
MessageParcel reply;
|
||||
MessageOption option;
|
||||
int32_t missionId = *(reinterpret_cast<const int32_t*>(data));
|
||||
int32_t state = *(reinterpret_cast<const int32_t*>(data));
|
||||
dataParcel.WriteInterfaceToken(DMS_STUB_INTERFACE_TOKEN);
|
||||
dataParcel.WriteInt32(missionId);
|
||||
dataParcel.WriteInt32(state);
|
||||
DelayedSingleton<DistributedSchedService>::GetInstance()->OnRemoteRequest(code, dataParcel, reply, option);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Fuzzer entry point */
|
||||
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
|
||||
{
|
||||
OHOS::DistributedSchedule::StartRemoteAbilityInnerFuzzTest(data, size);
|
||||
OHOS::DistributedSchedule::ConnectRemoteAbilityInnerFuzzTest(data, size);
|
||||
OHOS::DistributedSchedule::DisconnectRemoteAbilityInnerFuzzTest(data, size);
|
||||
OHOS::DistributedSchedule::StartContinuationInnerFuzzTest(data, size);
|
||||
OHOS::DistributedSchedule::NotifyCompleteContinuationInnerFuzzTest(data, size);
|
||||
OHOS::DistributedSchedule::ContinueMissionInnerFuzzTest(data, size);
|
||||
OHOS::DistributedSchedule::ContinueMissionOfBundleNameInnerFuzzTest(data, size);
|
||||
OHOS::DistributedSchedule::GetMissionInfosInnerFuzzTest(data, size);
|
||||
OHOS::DistributedSchedule::RegisterMissionListenerInnerFuzzTest(data, size);
|
||||
OHOS::DistributedSchedule::UnRegisterMissionListenerInnerFuzzTest(data, size);
|
||||
OHOS::DistributedSchedule::StartSyncRemoteMissionsInnerFuzzTest(data, size);
|
||||
OHOS::DistributedSchedule::StopSyncRemoteMissionsInnerFuzzTest(data, size);
|
||||
OHOS::DistributedSchedule::GetRemoteMissionSnapshotInfoInnerFuzzTest(data, size);
|
||||
OHOS::DistributedSchedule::StartRemoteAbilityByCallInnerFuzzTest(data, size);
|
||||
OHOS::DistributedSchedule::ReleaseRemoteAbilityInnerFuzzTest(data, size);
|
||||
OHOS::DistributedSchedule::GetDistributedComponentListInnerFuzzTest(data, size);
|
||||
OHOS::DistributedSchedule::StartRemoteFreeInstallInnerFuzzTest(data, size);
|
||||
OHOS::DistributedSchedule::StartRemoteShareFormInnerFuzzTest(data, size);
|
||||
OHOS::DistributedSchedule::StopRemoteExtensionAbilityInnerFuzzTest(data, size);
|
||||
OHOS::DistributedSchedule::RegisterOnListenerInnerFuzzTest(data, size);
|
||||
OHOS::DistributedSchedule::RegisterOffListenerInnerFuzzTest(data, size);
|
||||
OHOS::DistributedSchedule::RegisterDSchedEventListenerInnerFuzzTest(data, size);
|
||||
OHOS::DistributedSchedule::UnRegisterDSchedEventListenerInnerFuzzTest(data, size);
|
||||
OHOS::DistributedSchedule::SetMissionContinueStateInnerFuzzTest(data, size);
|
||||
return 0;
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
/*
|
||||
* Copyright (c) 2024 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef OHOS_DISTRIBUTEDSCHEDSTUB_FUZZER_H
|
||||
#define OHOS_DISTRIBUTEDSCHEDSTUB_FUZZER_H
|
||||
|
||||
#define FUZZ_PROJECT_NAME "distributedschedstub_fuzzer"
|
||||
|
||||
#endif
|
54
test/fuzztest/distributedschedstub_fuzzer/fuzz_util.cpp
Normal file
54
test/fuzztest/distributedschedstub_fuzzer/fuzz_util.cpp
Normal file
@ -0,0 +1,54 @@
|
||||
/*
|
||||
* 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 "fuzz_util.h"
|
||||
|
||||
#include "accesstoken_kit.h"
|
||||
#include "nativetoken_kit.h"
|
||||
#include "token_setproc.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedSchedule {
|
||||
namespace {
|
||||
constexpr const char* FOUNDATION_PROCESS_NAME = "foundation";
|
||||
}
|
||||
|
||||
void FuzzUtil::MockPermission()
|
||||
{
|
||||
static const char *perms[] = {
|
||||
"ohos.permission.DISTRIBUTED_DATASYNC"
|
||||
};
|
||||
MockProcessAndPermission(FOUNDATION_PROCESS_NAME, perms, 1);
|
||||
}
|
||||
|
||||
void FuzzUtil::MockProcessAndPermission(const char* processName, const char *perms[], int32_t permsNum)
|
||||
{
|
||||
uint64_t tokenId;
|
||||
NativeTokenInfoParams infoInstance = {
|
||||
.dcapsNum = 0,
|
||||
.permsNum = permsNum,
|
||||
.aclsNum = 0,
|
||||
.dcaps = nullptr,
|
||||
.perms = perms,
|
||||
.acls = nullptr,
|
||||
.processName = processName,
|
||||
.aplStr = "system_core",
|
||||
};
|
||||
tokenId = GetAccessTokenId(&infoInstance);
|
||||
SetSelfTokenID(tokenId);
|
||||
OHOS::Security::AccessToken::AccessTokenKit::ReloadNativeTokenInfo();
|
||||
}
|
||||
}
|
||||
}
|
31
test/fuzztest/distributedschedstub_fuzzer/fuzz_util.h
Normal file
31
test/fuzztest/distributedschedstub_fuzzer/fuzz_util.h
Normal file
@ -0,0 +1,31 @@
|
||||
/*
|
||||
* 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 MOCK_PERMISSION_H
|
||||
#define MOCK_PERMISSION_H
|
||||
|
||||
#include "iservice_registry.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedSchedule {
|
||||
class FuzzUtil {
|
||||
public:
|
||||
static void MockPermission();
|
||||
static void MockProcessAndPermission(const char* processName,
|
||||
const char *perms[], int32_t permsNum);
|
||||
};
|
||||
}
|
||||
} // namespace OHOS
|
||||
#endif // SAMGR_SERVICES_SAMGR_MOCK_PERMISSION_H
|
25
test/fuzztest/distributedschedstub_fuzzer/project.xml
Normal file
25
test/fuzztest/distributedschedstub_fuzzer/project.xml
Normal file
@ -0,0 +1,25 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Copyright (c) 2024 Huawei Device Co., Ltd.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
-->
|
||||
<fuzz_config>
|
||||
<fuzztest>
|
||||
<!-- maximum length of a test input -->
|
||||
<max_len>1000</max_len>
|
||||
<!-- maximum total time in seconds to run the fuzzer -->
|
||||
<max_total_time>300</max_total_time>
|
||||
<!-- memory usage limit in Mb -->
|
||||
<rss_limit_mb>4096</rss_limit_mb>
|
||||
</fuzztest>
|
||||
</fuzz_config>
|
Loading…
Reference in New Issue
Block a user