补充fuzz用例:1

Signed-off-by: wangjin_123 <wangjin193@huawei.com>
This commit is contained in:
w00675913 2024-02-01 19:29:05 +08:00 committed by wangjin_123
parent 875f5c4b8e
commit 1f3b8feecd
8 changed files with 233 additions and 18 deletions

View File

@ -143,8 +143,9 @@
"//foundation/barrierfree/accessibility/frameworks/acfwk/test:unittest",
"//foundation/barrierfree/accessibility/frameworks/asacfwk/test:unittest",
"//foundation/barrierfree/accessibility/frameworks/common/test:unittest",
"//foundation/barrierfree/accessibility/common/interface/test:unittest",
"//foundation/barrierfree/accessibility/common/interface/test/unittest:unittest",
"//foundation/barrierfree/accessibility/interfaces/innerkits/test/fuzztest:fuzztest",
"//foundation/barrierfree/accessibility/common/interface/test/fuzztest:fuzztest",
"//foundation/barrierfree/accessibility/interfaces/innerkits/test/benchmarktest:benchmarktest"
]
}

View File

@ -0,0 +1,25 @@
# 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.
config("configs_cc_ld") {
cflags = [
"-g",
"-O0",
"-Wno-unused-variable",
"-fno-omit-frame-pointer",
]
}
group("fuzztest") {
testonly = true
deps = [ "accessibilityelementoperatorcallbackstub_fuzzer:fuzztest" ]
}

View File

@ -0,0 +1,50 @@
# 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.
#####################hydra-fuzz###################
import("//build/config/features.gni")
import("//build/test.gni")
##############################fuzztest##########################################
ohos_fuzztest("AccessibilityElementOperatorCallbackStubFuzzTest") {
module_out_path = "accessibility/accessibility"
fuzz_config_file =
"../../fuzztest/accessibilityelementoperatorcallbackstub_fuzzer"
include_dirs = [ "../../../../../common/interface/include" ]
configs = [
"../../fuzztest:configs_cc_ld",
"../../../../../resources/config/build:coverage_flags",
]
sources = [ "accessibilityelementoperatorcallbackstub_fuzzer.cpp" ]
deps = [
"../../../../../interfaces/innerkits/common:accessibility_common",
"../../../../interface:accessibility_interface",
]
external_deps = [
"c_utils:utils",
"input:libmmi-client",
"ipc:ipc_single",
]
}
###############################################################################
group("fuzztest") {
testonly = true
deps = []
deps += [
# deps file
":AccessibilityElementOperatorCallbackStubFuzzTest",
]
}
###############################################################################

View File

@ -0,0 +1,80 @@
/*
* 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 "accessibilityelementoperatorcallbackstub_fuzzer.h"
#include "accessibility_element_operator_callback_stub.h"
#include "securec.h"
namespace OHOS {
namespace Accessibility {
namespace {
constexpr size_t DATA_MIN_SIZE = 100;
constexpr char END_CHAR = '\0';
constexpr size_t LEN = 10;
}
class ElementOperatorCallbackImplFuzzTest : public AccessibilityElementOperatorCallbackStub {
public:
ElementOperatorCallbackImplFuzzTest() = default;
~ElementOperatorCallbackImplFuzzTest() = default;
void SetSearchElementInfoByAccessibilityIdResult(const std::vector<AccessibilityElementInfo> &infos,
const int32_t requestId) override {}
void SetSearchElementInfoByTextResult(const std::vector<AccessibilityElementInfo> &infos,
const int32_t requestId) override {}
void SetFindFocusedElementInfoResult(const AccessibilityElementInfo &info,
const int32_t requestId) override {}
void SetFocusMoveSearchResult(const AccessibilityElementInfo &info, const int32_t requestId) override {}
void SetExecuteActionResult(const bool succeeded, const int32_t requestId) override {}
};
template<class T>
size_t GetObject(T &object, const uint8_t *data, size_t size)
{
size_t objectSize = sizeof(object);
if (objectSize > size) {
return 0;
}
return memcpy_s(&object, objectSize, data, objectSize) == EOK ? objectSize : 0;
}
bool OnRemoteRequestFuzzTest(const uint8_t* data, size_t size)
{
if (data == nullptr || size < DATA_MIN_SIZE) {
return false;
}
size_t position = 0;
uint32_t code = 0;
MessageParcel mdata;
MessageParcel reply;
MessageOption option(MessageOption::TF_SYNC);
position += GetObject<uint32_t>(code, &data[position], size - position);
ElementOperatorCallbackImplFuzzTest callBackImp;
mdata.WriteInterfaceToken(ElementOperatorCallbackImplFuzzTest::GetDescriptor());
callBackImp.OnRemoteRequest(code, mdata, reply, option);
return true;
}
} // namespace Accessibility
} // namespace OHOS
/* Fuzzer entry point */
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
{
/* Run your code on data */
OHOS::Accessibility::OnRemoteRequestFuzzTest(data, size);
return 0;
}

View File

@ -0,0 +1,20 @@
/*
* 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 ACCESSIBILITYELEMENTOPERATORCALLBACKSTUB_FUZZER_H
#define ACCESSIBILITYELEMENTOPERATORCALLBACKSTUB_FUZZER_H
#define FUZZ_PROJECT_NAME "accessibilityelementoperatorcallbackstub_fuzzer"
#endif // ACCESSIBILITYELEMENTOPERATORCALLBACKSTUB_FUZZER_H

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

@ -23,9 +23,9 @@ config("module_parcel_private_config") {
cflags += [ "-DBINDER_IPC_32BIT" ]
}
include_dirs = [
"../include/parcel",
"../../../common/log/include",
"../../../interfaces/innerkits/common/include",
"../../include/parcel",
"../../../../common/log/include",
"../../../../interfaces/innerkits/common/include",
]
defines = [
"AAMS_LOG_TAG = \"accessibility_parcel\"",
@ -34,19 +34,19 @@ config("module_parcel_private_config") {
}
accessibility_parcel_src = [
"../src/parcel/accessibility_ability_info_parcel.cpp",
"../src/parcel/accessibility_caption_parcel.cpp",
"../src/parcel/accessibility_element_info_parcel.cpp",
"../src/parcel/accessibility_event_info_parcel.cpp",
"../src/parcel/accessibility_window_info_parcel.cpp",
"../../src/parcel/accessibility_ability_info_parcel.cpp",
"../../src/parcel/accessibility_caption_parcel.cpp",
"../../src/parcel/accessibility_element_info_parcel.cpp",
"../../src/parcel/accessibility_event_info_parcel.cpp",
"../../src/parcel/accessibility_window_info_parcel.cpp",
]
accessibility_parcel_test_src = [
"unittest/accessibility_ability_info_parcel_test.cpp",
"unittest/accessibility_caption_parcel_test.cpp",
"unittest/accessibility_element_info_parcel_test.cpp",
"unittest/accessibility_event_info_parcel_test.cpp",
"unittest/accessibility_window_info_parcel_test.cpp",
"accessibility_ability_info_parcel_test.cpp",
"accessibility_caption_parcel_test.cpp",
"accessibility_element_info_parcel_test.cpp",
"accessibility_event_info_parcel_test.cpp",
"accessibility_window_info_parcel_test.cpp",
]
ohos_unittest("accessibility_parcel_test") {
@ -57,13 +57,13 @@ ohos_unittest("accessibility_parcel_test") {
configs = [
":module_parcel_private_config",
"../../../resources/config/build:coverage_flags",
"../../../../resources/config/build:coverage_flags",
]
deps = [
"../../../../../../third_party/googletest:gmock_main",
"../../../../../../third_party/googletest:gtest_main",
"../../../interfaces/innerkits/common:accessibility_common",
"../../../../../../../third_party/googletest:gmock_main",
"../../../../../../../third_party/googletest:gtest_main",
"../../../../interfaces/innerkits/common:accessibility_common",
]
external_deps = [