add window extension client fuzz test

Signed-off-by: shenguiming <shenguiming5@h-partners.com>
This commit is contained in:
shenguiming 2024-05-14 09:18:52 +08:00
parent c5e8ece4f3
commit a92cc9d6a5
6 changed files with 199 additions and 0 deletions

View File

@ -21,5 +21,6 @@ group("fuzztest") {
"screensessionmgrstubstate_fuzzer:fuzztest",
"screensessionmgrstubwake_fuzzer:fuzztest",
"sessioninterface_fuzzer:fuzztest",
"windowextensionclstub_fuzzer:fuzztest",
]
}

View File

@ -0,0 +1,64 @@
# 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("WindowExtensionClStubFuzzTest") {
fuzz_config_file = "."
module_out_path = module_output_path
include_dirs = [
"${window_base_path}/window_scene/session_manager/include",
"${window_base_path}/extension/extension_connection/include",
"${window_base_path}/extension/extension_connection/include/zidl",
"${window_base_path}/extension/window_extension/include",
"${window_base_path}/extension/window_extension/include/zidl",
"${window_base_path}/interfaces/innerkits/extension",
]
cflags = [
"-g",
"-O0",
"-fno-omit-frame-pointer",
]
sources = [ "windowextensionclstub_fuzzer.cpp" ]
deps = [
"${window_base_path}/extension/window_extension:libwindow_extension",
"${window_base_path}/utils:libwmutil",
"${window_base_path}/window_scene/session:scene_session",
"${window_base_path}/window_scene/session_manager:session_manager",
"${window_base_path}/extension/extension_connection:libwindow_extension_client",
]
external_deps = [
"c_utils:utils",
"hilog:libhilog",
"ipc:ipc_single",
]
}
###############################################################################
group("fuzztest") {
testonly = true
deps = []
deps += [
# deps file
":WindowExtensionClStubFuzzTest",
]
}
###############################################################################

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,74 @@
/*
* 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 "window_extension_client_interface.h"
#include "window_extension_client_stub.h"
#include "window_extension_client_stub_impl.h"
#include "windowextensionclstub_fuzzer.h"
using namespace OHOS::Rosen;
namespace OHOS {
namespace {
constexpr size_t DATA_MIN_SIZE = 2;
}
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(WindowExtensionClientStub::GetDescriptor());
parcel.WriteBuffer(data, size);
parcel.RewindRead(0);
sptr<IWindowExtensionCallback> componentCallback;
std::shared_ptr<WindowExtensionClientStubImpl> extensionStubClient = std::make_shared<WindowExtensionClientStubImpl>(componentCallback);
extensionStubClient->OnRemoteRequest(
static_cast<uint32_t>(IWindowExtensionClient::TRANS_ID_ON_WINDOW_READY),
parcel, reply, option);
extensionStubClient->OnRemoteRequest(
static_cast<uint32_t>(IWindowExtensionClient::TRANS_ID_ON_BACK_PRESS),
parcel, reply, option);
extensionStubClient->OnRemoteRequest(
static_cast<uint32_t>(IWindowExtensionClient::TRANS_ID_ON_KEY_EVENT),
parcel, reply, option);
extensionStubClient->OnRemoteRequest(
static_cast<uint32_t>(IWindowExtensionClient::TRANS_ID_ON_POINTER_EVENT),
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

@ -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_WINDOW_EXTENSIONCL_STUB_FUZZER_H
#define TEST_FUZZTEST_WINDOW_EXTENSIONCL_STUB_FUZZER_H
#define FUZZ_PROJECT_NAME "windowextensionclstub_fuzzer"
#endif