!6374 session stub fuzz用例补充code

Merge pull request !6374 from wangjian10/master
This commit is contained in:
openharmony_ci 2024-05-21 08:05:36 +00:00 committed by Gitee
commit d5749aa322
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
15 changed files with 344 additions and 47 deletions

View File

@ -18,7 +18,7 @@ import("../../../../windowmanager_aafwk.gni")
module_output_path = "window_manager/window_manager"
##############################fuzztest##########################################
ohos_fuzztest("SessionStubUpdateFuzzTest") {
ohos_fuzztest("SessionStubBaseFuzzTest") {
fuzz_config_file = "."
module_out_path = module_output_path
@ -28,7 +28,7 @@ ohos_fuzztest("SessionStubUpdateFuzzTest") {
"-O0",
"-fno-omit-frame-pointer",
]
sources = [ "sessionstubupdate_fuzzer.cpp" ]
sources = [ "sessionstubbase_fuzzer.cpp" ]
deps = [
"${window_base_path}/dm:libdm",
"${window_base_path}/utils:libwmutil",
@ -54,7 +54,7 @@ group("fuzztest") {
deps += [
# deps file
":SessionStubUpdateFuzzTest",
":SessionStubBaseFuzzTest",
]
}
###############################################################################

View File

@ -25,13 +25,13 @@
#include "session/host/include/zidl/session_ipc_interface_code.h"
#include "session/host/include/zidl/session_stub.h"
#include "session/host/include/session.h"
#include "sessionstubconnect_fuzzer.h"
#include "sessionstubbase_fuzzer.h"
using namespace OHOS::Rosen;
namespace OHOS {
namespace {
constexpr size_t DATA_MIN_SIZE = 2;
constexpr size_t DATA_MIN_SIZE = 2;
}
bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size)
@ -51,24 +51,33 @@ bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size)
SessionInfo info;
info.abilityName_ = "stubConnectFuzzTest";
info.bundleName_ = "stubConnectFuzzTest";
std::shared_ptr<Session> sessionStub = std::make_shared<Session>(info);
sessionStub->OnRemoteRequest(
static_cast<uint32_t>(Rosen::SessionInterfaceCode::TRANS_ID_CONNECT),
sptr<Session> sessionStub = new (std::nothrow) Session(info);
if (sessionStub == nullptr) {
return false;
}
sessionStub->OnRemoteRequest(static_cast<uint32_t>(Rosen::SessionInterfaceCode::TRANS_ID_CONNECT),
parcel, reply, option);
sessionStub->OnRemoteRequest(static_cast<uint32_t>(Rosen::SessionInterfaceCode::TRANS_ID_DISCONNECT),
parcel, reply, option);
sessionStub->OnRemoteRequest(static_cast<uint32_t>(Rosen::SessionInterfaceCode::TRANS_ID_FOREGROUND),
parcel, reply, option);
sessionStub->OnRemoteRequest(static_cast<uint32_t>(Rosen::SessionInterfaceCode::TRANS_ID_BACKGROUND),
parcel, reply, option);
sessionStub->OnRemoteRequest(static_cast<uint32_t>(Rosen::SessionInterfaceCode::TRANS_ID_SHOW),
parcel, reply, option);
sessionStub->OnRemoteRequest(static_cast<uint32_t>(Rosen::SessionInterfaceCode::TRANS_ID_HIDE),
parcel, reply, option);
sessionStub->OnRemoteRequest(
static_cast<uint32_t>(Rosen::SessionInterfaceCode::TRANS_ID_DISCONNECT),
static_cast<uint32_t>(Rosen::SessionInterfaceCode::TRANS_ID_CHANGE_SESSION_VISIBILITY_WITH_STATUS_BAR),
parcel, reply, option);
sessionStub->OnRemoteRequest(
static_cast<uint32_t>(Rosen::SessionInterfaceCode::TRANS_ID_FOREGROUND),
sessionStub->OnRemoteRequest(static_cast<uint32_t>(Rosen::SessionInterfaceCode::TRANS_ID_ACTIVE_PENDING_SESSION),
parcel, reply, option);
sessionStub->OnRemoteRequest(
static_cast<uint32_t>(Rosen::SessionInterfaceCode::TRANS_ID_BACKGROUND),
sessionStub->OnRemoteRequest(static_cast<uint32_t>(Rosen::SessionInterfaceCode::TRANS_ID_UPDATE_ACTIVE_STATUS),
parcel, reply, option);
sessionStub->OnRemoteRequest(
static_cast<uint32_t>(Rosen::SessionInterfaceCode::TRANS_ID_SHOW),
sessionStub->OnRemoteRequest(static_cast<uint32_t>(Rosen::SessionInterfaceCode::TRANS_ID_TERMINATE),
parcel, reply, option);
sessionStub->OnRemoteRequest(
static_cast<uint32_t>(Rosen::SessionInterfaceCode::TRANS_ID_HIDE),
sessionStub->OnRemoteRequest(static_cast<uint32_t>(Rosen::SessionInterfaceCode::TRANS_ID_EXCEPTION),
parcel, reply, option);
return true;
}

View File

@ -13,9 +13,9 @@
* limitations under the License.
*/
#ifndef TEST_FUZZTEST_SESSION_STUB_UPDATE_FUZZER_H
#define TEST_FUZZTEST_SESSION_STUB_UPDATE_FUZZER_H
#ifndef TEST_FUZZTEST_SESSION_STUB_BASE_FUZZER_H
#define TEST_FUZZTEST_SESSION_STUB_BASE_FUZZER_H
#define FUZZ_PROJECT_NAME "sessionstubupdate_fuzzer"
#define FUZZ_PROJECT_NAME "sessionstubbase_fuzzer"
#endif

View File

@ -0,0 +1,60 @@
# 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.
import("//build/config/features.gni")
import("//build/test.gni")
import("../../../../windowmanager_aafwk.gni")
module_output_path = "window_manager/window_manager"
##############################fuzztest##########################################
ohos_fuzztest("SessionStubExtensionFuzzTest") {
fuzz_config_file = "."
module_out_path = module_output_path
include_dirs = [ "${window_base_path}/window_scene/session_manager/include" ]
cflags = [
"-g",
"-O0",
"-fno-omit-frame-pointer",
]
sources = [ "sessionstubextension_fuzzer.cpp" ]
deps = [
"${window_base_path}/dm:libdm",
"${window_base_path}/utils:libwmutil",
"${window_base_path}/window_scene/common:window_scene_common",
"${window_base_path}/window_scene/session:scene_session",
"${window_base_path}/window_scene/session_manager:screen_session_manager",
"${window_base_path}/window_scene/session_manager:session_manager",
]
external_deps = [
"accessibility:accessibility_common",
"accessibility:accessibility_interface",
"c_utils:utils",
"hilog:libhilog",
"ipc:ipc_single",
]
}
###############################################################################
group("fuzztest") {
testonly = true
deps = []
deps += [
# deps file
":SessionStubExtensionFuzzTest",
]
}
###############################################################################

View File

@ -25,13 +25,53 @@
#include "session/host/include/zidl/session_ipc_interface_code.h"
#include "session/host/include/zidl/session_stub.h"
#include "session/host/include/session.h"
#include "sessionstubupdate_fuzzer.h"
#include "sessionstubextension_fuzzer.h"
using namespace OHOS::Rosen;
namespace OHOS {
namespace {
constexpr size_t DATA_MIN_SIZE = 2;
constexpr size_t DATA_MIN_SIZE = 2;
}
void SessionStubTestExtensionCode(sptr<Session> sessionStub, MessageParcel& parcel,
MessageParcel& reply, MessageOption& option)
{
sessionStub->OnRemoteRequest(static_cast<uint32_t>(Rosen::SessionInterfaceCode::TRANS_ID_TRANSFER_ABILITY_RESULT),
parcel, reply, option);
sessionStub->OnRemoteRequest(
static_cast<uint32_t>(Rosen::SessionInterfaceCode::TRANS_ID_TRANSFER_EXTENSION_DATA),
parcel, reply, option);
sessionStub->OnRemoteRequest(
static_cast<uint32_t>(Rosen::SessionInterfaceCode::TRANS_ID_NOTIFY_REMOTE_READY),
parcel, reply, option);
sessionStub->OnRemoteRequest(
static_cast<uint32_t>(Rosen::SessionInterfaceCode::TRANS_ID_NOTIFY_EXTENSION_DIED),
parcel, reply, option);
sessionStub->OnRemoteRequest(
static_cast<uint32_t>(Rosen::SessionInterfaceCode::TRANS_ID_NOTIFY_ASYNC_ON),
parcel, reply, option);
sessionStub->OnRemoteRequest(
static_cast<uint32_t>(Rosen::SessionInterfaceCode::TRANS_ID_NOTIFY_SYNC_ON),
parcel, reply, option);
sessionStub->OnRemoteRequest(
static_cast<uint32_t>(Rosen::SessionInterfaceCode::TRANS_ID_TRIGGER_BIND_MODAL_UI_EXTENSION),
parcel, reply, option);
sessionStub->OnRemoteRequest(static_cast<uint32_t>(Rosen::SessionInterfaceCode::TRANS_ID_NOTIFY_EXTENSION_TIMEOUT),
parcel, reply, option);
return;
}
void SessionStubTestPipCode(sptr<Session> sessionStub, MessageParcel& parcel,
MessageParcel& reply, MessageOption& option)
{
sessionStub->OnRemoteRequest(
static_cast<uint32_t>(Rosen::SessionInterfaceCode::TRANS_ID_NOTIFY_PIP_WINDOW_PREPARE_CLOSE),
parcel, reply, option);
sessionStub->OnRemoteRequest(
static_cast<uint32_t>(Rosen::SessionInterfaceCode::TRANS_ID_UPDATE_PIP_RECT),
parcel, reply, option);
return;
}
bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size)
@ -51,25 +91,13 @@ bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size)
SessionInfo info;
info.abilityName_ = "stubConnectFuzzTest";
info.bundleName_ = "stubConnectFuzzTest";
std::shared_ptr<Session> sessionStub = std::make_shared<Session>(info);
sessionStub->OnRemoteRequest(
static_cast<uint32_t>(Rosen::SessionInterfaceCode::TRANS_ID_UPDATE_RECTCHANGE_LISTENER_REGISTERED),
parcel, reply, option);
sessionStub->OnRemoteRequest(
static_cast<uint32_t>(Rosen::SessionInterfaceCode::TRANS_ID_UPDATE_ACTIVE_STATUS),
parcel, reply, option);
sessionStub->OnRemoteRequest(
static_cast<uint32_t>(Rosen::SessionInterfaceCode::TRANS_ID_UPDATE_SESSION_RECT),
parcel, reply, option);
sessionStub->OnRemoteRequest(
static_cast<uint32_t>(Rosen::SessionInterfaceCode::TRANS_ID_UPDATE_WINDOW_ANIMATION_FLAG),
parcel, reply, option);
sessionStub->OnRemoteRequest(
static_cast<uint32_t>(Rosen::SessionInterfaceCode::TRANS_ID_UPDATE_CUSTOM_ANIMATION),
parcel, reply, option);
sessionStub->OnRemoteRequest(
static_cast<uint32_t>(Rosen::SessionInterfaceCode::TRANS_ID_UPDATE_PIP_RECT),
parcel, reply, option);
sptr<Session> sessionStub = new (std::nothrow) Session(info);
if (sessionStub == nullptr) {
return false;
}
SessionStubTestExtensionCode(sessionStub, parcel, reply, option);
SessionStubTestPipCode(sessionStub, parcel, reply, option);
return true;
}
} // namespace.OHOS

View 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.
*/
#ifndef TEST_FUZZTEST_SESSION_STUB_EXTENSION_FUZZER_H
#define TEST_FUZZTEST_SESSION_STUB_EXTENSION_FUZZER_H
#define FUZZ_PROJECT_NAME "sessionstubextension_fuzzer"
#endif

View File

@ -18,7 +18,7 @@ import("../../../../windowmanager_aafwk.gni")
module_output_path = "window_manager/window_manager"
##############################fuzztest##########################################
ohos_fuzztest("SessionStubConnectFuzzTest") {
ohos_fuzztest("SessionStubSceneFuzzTest") {
fuzz_config_file = "."
module_out_path = module_output_path
@ -28,7 +28,7 @@ ohos_fuzztest("SessionStubConnectFuzzTest") {
"-O0",
"-fno-omit-frame-pointer",
]
sources = [ "sessionstubconnect_fuzzer.cpp" ]
sources = [ "sessionstubscene_fuzzer.cpp" ]
deps = [
"${window_base_path}/dm:libdm",
"${window_base_path}/utils:libwmutil",
@ -54,7 +54,7 @@ group("fuzztest") {
deps += [
# deps file
":SessionStubConnectFuzzTest",
":SessionStubSceneFuzzTest",
]
}
###############################################################################

View File

@ -0,0 +1,14 @@
# 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

View 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>

View File

@ -0,0 +1,140 @@
/*
* 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.
*/
#include <cstddef>
#include <cstdint>
#include <parcel.h>
#include <securec.h>
#include <iremote_stub.h>
#include "message_option.h"
#include "message_parcel.h"
#include "marshalling_helper.h"
#include "session/host/include/zidl/session_ipc_interface_code.h"
#include "session/host/include/zidl/session_stub.h"
#include "session/host/include/session.h"
#include "sessionstubscene_fuzzer.h"
using namespace OHOS::Rosen;
namespace OHOS {
namespace {
constexpr size_t DATA_MIN_SIZE = 2;
}
void SessionStubTestUpdateCode(sptr<Session> sessionStub, MessageParcel& parcel,
MessageParcel& reply, MessageOption& option)
{
sessionStub->OnRemoteRequest(static_cast<uint32_t>(Rosen::SessionInterfaceCode::TRANS_ID_UPDATE_CUSTOM_ANIMATION),
parcel, reply, option);
sessionStub->OnRemoteRequest(
static_cast<uint32_t>(Rosen::SessionInterfaceCode::TRANS_ID_UPDATE_WINDOW_ANIMATION_FLAG),
parcel, reply, option);
sessionStub->OnRemoteRequest(
static_cast<uint32_t>(Rosen::SessionInterfaceCode::TRANS_ID_UPDATE_RECTCHANGE_LISTENER_REGISTERED),
parcel, reply, option);
sessionStub->OnRemoteRequest(
static_cast<uint32_t>(Rosen::SessionInterfaceCode::TRANS_ID_UPDATE_SESSION_RECT),
parcel, reply, option);
sessionStub->OnRemoteRequest(
static_cast<uint32_t>(Rosen::SessionInterfaceCode::TRANS_ID_UPDATE_CUSTOM_ANIMATION),
parcel, reply, option);
sessionStub->OnRemoteRequest(
static_cast<uint32_t>(Rosen::SessionInterfaceCode::TRANS_ID_UPDATE_SESSION_PROPERTY),
parcel, reply, option);
sessionStub->OnRemoteRequest(
static_cast<uint32_t>(Rosen::SessionInterfaceCode::TRANS_ID_SEND_POINTEREVENT_FOR_MOVE_DRAG),
parcel, reply, option);
sessionStub->OnRemoteRequest(static_cast<uint32_t>(Rosen::SessionInterfaceCode::TRANS_ID_RAISE_TO_APP_TOP),
parcel, reply, option);
sessionStub->OnRemoteRequest(static_cast<uint32_t>(Rosen::SessionInterfaceCode::TRANS_ID_RAISE_ABOVE_TARGET),
parcel, reply, option);
sessionStub->OnRemoteRequest(static_cast<uint32_t>(Rosen::SessionInterfaceCode::TRANS_ID_RAISE_APP_MAIN_WINDOW),
parcel, reply, option);
sessionStub->OnRemoteRequest(static_cast<uint32_t>(Rosen::SessionInterfaceCode::TRANS_ID_NEED_AVOID),
parcel, reply, option);
sessionStub->OnRemoteRequest(
static_cast<uint32_t>(Rosen::SessionInterfaceCode::TRANS_ID_ADJUST_KEYBOARD_LAYOUT),
parcel, reply, option);
return;
}
void SessionStubTestSetCode(sptr<Session> sessionStub, MessageParcel& parcel,
MessageParcel& reply, MessageOption& option)
{
sessionStub->OnRemoteRequest(static_cast<uint32_t>(Rosen::SessionInterfaceCode::TRANS_ID_SET_MAXIMIZE_MODE),
parcel, reply, option);
sessionStub->OnRemoteRequest(
static_cast<uint32_t>(Rosen::SessionInterfaceCode::TRANS_ID_SET_LANDSCAPE_MULTI_WINDOW),
parcel, reply, option);
sessionStub->OnRemoteRequest(
static_cast<uint32_t>(Rosen::SessionInterfaceCode::TRANS_ID_SET_KEYBOARD_SESSION_GRAVITY),
parcel, reply, option);
sessionStub->OnRemoteRequest(static_cast<uint32_t>(Rosen::SessionInterfaceCode::TRANS_ID_SET_CALLING_SESSION_ID),
parcel, reply, option);
sessionStub->OnRemoteRequest(
static_cast<uint32_t>(Rosen::SessionInterfaceCode::TRANS_ID_SET_CUSTOM_DECOR_HEIGHT),
parcel, reply, option);
sessionStub->OnRemoteRequest(static_cast<uint32_t>(Rosen::SessionInterfaceCode::TRANS_ID_MARK_PROCESSED),
parcel, reply, option);
sessionStub->OnRemoteRequest(static_cast<uint32_t>(Rosen::SessionInterfaceCode::TRANS_ID_SESSION_EVENT),
parcel, reply, option);
sessionStub->OnRemoteRequest(static_cast<uint32_t>(Rosen::SessionInterfaceCode::TRANS_ID_BACKPRESSED),
parcel, reply, option);
sessionStub->OnRemoteRequest(static_cast<uint32_t>(Rosen::SessionInterfaceCode::TRANS_ID_GET_AVOID_AREA),
parcel, reply, option);
sessionStub->OnRemoteRequest(static_cast<uint32_t>(Rosen::SessionInterfaceCode::TRANS_ID_GET_MAXIMIZE_MODE),
parcel, reply, option);
sessionStub->OnRemoteRequest(
static_cast<uint32_t>(Rosen::SessionInterfaceCode::TRANS_ID_PROCESS_POINT_DOWN_SESSION),
parcel, reply, option);
return;
}
bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size)
{
if (data == nullptr || size < DATA_MIN_SIZE) {
return false;
}
MessageParcel parcel;
MessageParcel reply;
MessageOption option;
parcel.WriteInterfaceToken(SessionStub::GetDescriptor());
parcel.WriteBuffer(data, size);
parcel.RewindRead(0);
SessionInfo info;
info.abilityName_ = "stubConnectFuzzTest";
info.bundleName_ = "stubConnectFuzzTest";
sptr<Session> sessionStub = new (std::nothrow) Session(info);
if (sessionStub == nullptr) {
return false;
}
SessionStubTestUpdateCode(sessionStub, parcel, reply, option);
SessionStubTestSetCode(sessionStub, parcel, reply, option);
return true;
}
} // namespace.OHOS
/* Fuzzer entry point */
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
{
/* Run your code on data */
OHOS::DoSomethingInterestingWithMyAPI(data, size);
return 0;
}

View File

@ -13,9 +13,9 @@
* limitations under the License.
*/
#ifndef TEST_FUZZTEST_SESSION_STUB_CONNECT_FUZZER_H
#define TEST_FUZZTEST_SESSION_STUB_CONNECT_FUZZER_H
#ifndef TEST_FUZZTEST_SESSION_STUB_SCENE_FUZZER_H
#define TEST_FUZZTEST_SESSION_STUB_SCENE_FUZZER_H
#define FUZZ_PROJECT_NAME "sessionstubconnect_fuzzer"
#define FUZZ_PROJECT_NAME "sessionstubscene_fuzzer"
#endif