!159 无障碍fuzz测试case提交

Merge pull request !159 from Mupceet/release_0531_fuzzcase
This commit is contained in:
openharmony_ci 2022-05-31 07:31:43 +00:00 committed by Gitee
commit 3c48bb2624
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
12 changed files with 1099 additions and 2 deletions

View File

@ -14,5 +14,9 @@
group("fuzztest") {
testonly = true
deps = [ "accessibilityconfig_fuzzer:fuzztest" ]
deps = [
"accessibilityconfig_fuzzer:fuzztest",
"accessibilitysystemabilityclient_fuzzer:fuzztest",
"accessibleabilityclient_fuzzer:fuzztest",
]
}

View File

@ -18,7 +18,7 @@
namespace OHOS {
namespace {
constexpr size_t DATA_MIN_SIZE = 46;
constexpr size_t DATA_MIN_SIZE = 98;
constexpr char END_CHAR = '\0';
constexpr size_t LEN = 10;
} // namespace
@ -76,20 +76,52 @@ bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size)
size_t startPos = 0;
abConfig.SetScreenMagnificationState(data[startPos++] & 0x01);
abConfig.SetMouseKeyState(data[startPos++] & 0x01);
abConfig.SetCaptionState(data[startPos++] & 0x01);
abConfig.SetHighContrastTextState(data[startPos++] & 0x01);
abConfig.SetInvertColorState(data[startPos++] & 0x01);
abConfig.SetAnimationOffState(data[startPos++] & 0x01);
abConfig.SetAudioMonoState(data[startPos++] & 0x01);
uint32_t temp = 0;
startPos += GetObject<uint32_t>(temp, &data[startPos], size - startPos);
abConfig.SetContentTimeout(temp);
startPos += GetObject<uint32_t>(temp, &data[startPos], size - startPos);
abConfig.SetDaltonizationColorFilter(static_cast<OHOS::AccessibilityConfig::DALTONIZATION_TYPE>(temp));
startPos += GetObject<uint32_t>(temp, &data[startPos], size - startPos);
abConfig.SetMouseAutoClick(static_cast<int32_t>(temp));
float tempFloat = 0;
startPos += GetObject<float>(tempFloat, &data[startPos], size - startPos);
abConfig.SetBrightnessDiscount(tempFloat);
startPos += GetObject<float>(tempFloat, &data[startPos], size - startPos);
abConfig.SetAudioBalance(tempFloat);
char name[LEN + 1];
name[LEN] = END_CHAR;
std::memcpy(&name, &data[startPos], LEN);
std::string nameStr(name);
abConfig.SetShortkeyTarget(nameStr);
startPos += LEN;
OHOS::AccessibilityConfig::CaptionProperty property;
startPos += GenerateCaptionProperty(property, &data[startPos], size - startPos);
abConfig.SetCaptionProperty(property);
std::memcpy(&name, &data[startPos], LEN);
std::string abilityName1(name);
startPos += LEN;
startPos += GetObject<uint32_t>(temp, &data[startPos], size - startPos);
abConfig.EnableAbility(abilityName1, temp);
std::memcpy(&name, &data[startPos], LEN);
std::string abilityName2(name);
startPos += LEN;
abConfig.DisableAbility(abilityName2);
return true;
}
}

View File

@ -0,0 +1,45 @@
# Copyright (c) 2021 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("AccessibilitySystemAbilityClientFuzzTest") {
module_out_path = "accessibility/asacfwk"
fuzz_config_file = "../../fuzztest/accessibilitysystemabilityclient_fuzzer"
include_dirs = []
cflags = [
"-g",
"-O0",
"-Wno-unused-variable",
"-fno-omit-frame-pointer",
]
sources = [ "accessibilitysystemabilityclient_fuzzer.cpp" ]
deps = [
"//base/accessibility/interfaces/innerkits/asacfwk:accessibilityclient",
]
}
###############################################################################
group("fuzztest") {
testonly = true
deps = []
deps += [
# deps file
":AccessibilitySystemAbilityClientFuzzTest",
]
}
###############################################################################

View File

@ -0,0 +1,254 @@
/*
* 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 "accessibilitysystemabilityclient_fuzzer.h"
#include "accessibility_system_ability_client.h"
namespace OHOS {
namespace Accessibility {
namespace {
constexpr size_t DATA_MIN_SIZE = 200;
constexpr char END_CHAR = '\0';
constexpr size_t LEN = 10;
}
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;
}
std::memcpy(&object, data, objectSize);
return objectSize;
}
class ElementOperatorForFuzzTest : public AccessibilityElementOperator {
public:
virtual ~ElementOperatorForFuzzTest() = default;
void SearchElementInfoByAccessibilityId(const int32_t elementId,
const int32_t requestId, AccessibilityElementOperatorCallback &callback, const int32_t mode) {}
void SearchElementInfosByText(const int32_t elementId, const std::string &text,
const int32_t requestId, AccessibilityElementOperatorCallback &callback) {}
void FindFocusedElementInfo(const int32_t elementId, const int32_t focusType, const int32_t requestId,
AccessibilityElementOperatorCallback &callback) {}
void FocusMoveSearch(const int32_t elementId, const int32_t direction, const int32_t requestId,
AccessibilityElementOperatorCallback &callback) {}
void ExecuteAction(const int32_t elementId, const int32_t action,
const std::map<std::string, std::string> &actionArguments,
const int32_t requestId, AccessibilityElementOperatorCallback &callback) {}
void ClearFocus() {}
void OutsideTouch() {}
};
class StateObserverForFuzzTest : public AccessibilityStateObserver {
public:
virtual ~StateObserverForFuzzTest() = default;
void OnStateChanged(const bool state) {}
};
static size_t CreateEventInfo(AccessibilityEventInfo &eventInfo, const uint8_t* data, size_t size)
{
size_t position = 0;
int32_t channelId = 0;
position += GetObject<int32_t>(channelId, &data[position], size - position);
eventInfo.SetChannelId(channelId);
int32_t componentId = 0;
position += GetObject<int32_t>(componentId, &data[position], size - position);
eventInfo.SetSource(componentId);
int32_t windowId = 0;
position += GetObject<int32_t>(windowId, &data[position], size - position);
eventInfo.SetWindowId(windowId);
int32_t index = 0;
position += GetObject<int32_t>(index, &data[position], size - position);
eventInfo.SetCurrentIndex(index);
position += GetObject<int32_t>(index, &data[position], size - position);
eventInfo.SetBeginIndex(index);
position += GetObject<int32_t>(index, &data[position], size - position);
eventInfo.SetEndIndex(index);
int32_t itemCounts = 0;
position += GetObject<int32_t>(itemCounts, &data[position], size - position);
eventInfo.SetItemCounts(itemCounts);
int32_t recordCount = 0;
position += GetObject<int32_t>(recordCount, &data[position], size - position);
eventInfo.SetRecordCount(recordCount);
WindowsContentChangeTypes changeTypes;
position += GetObject<WindowsContentChangeTypes>(changeTypes, &data[position], size - position);
eventInfo.SetWindowContentChangeTypes(changeTypes);
WindowUpdateType updateTypes;
position += GetObject<WindowUpdateType>(updateTypes, &data[position], size - position);
eventInfo.SetWindowChangeTypes(updateTypes);
EventType eventType;
position += GetObject<EventType>(eventType, &data[position], size - position);
eventInfo.SetEventType(eventType);
int64_t timeStamp = 0;
position += GetObject<int64_t>(timeStamp, &data[position], size - position);
eventInfo.SetTimeStamp(timeStamp);
TextMoveUnit granularity;
position += GetObject<TextMoveUnit>(granularity, &data[position], size - position);
eventInfo.SetTextMovementStep(granularity);
ActionType action;
position += GetObject<ActionType>(action, &data[position], size - position);
eventInfo.SetTriggerAction(action);
NotificationCategory category;
position += GetObject<NotificationCategory>(category, &data[position], size - position);
eventInfo.SetNotificationInfo(category);
GestureType gestureType;
position += GetObject<GestureType>(gestureType, &data[position], size - position);
eventInfo.SetGestureType(gestureType);
int32_t pageId = 0;
position += GetObject<int32_t>(pageId, &data[position], size - position);
eventInfo.SetPageId(pageId);
char name[LEN + 1];
name[LEN] = END_CHAR;
std::memcpy(&name, &data[position], LEN);
std::string className(name);
eventInfo.SetComponentType(className);
position += LEN;
std::memcpy(&name, &data[position], LEN);
std::string beforeText(name);
eventInfo.SetBeforeText(beforeText);
position += LEN;
std::memcpy(&name, &data[position], LEN);
std::string content(name);
eventInfo.AddContent(content);
position += LEN;
std::memcpy(&name, &data[position], LEN);
std::string lastContent(name);
eventInfo.SetLatestContent(lastContent);
position += LEN;
std::memcpy(&name, &data[position], LEN);
std::string contentDescription(name);
eventInfo.SetDescription(contentDescription);
position += LEN;
std::memcpy(&name, &data[position], LEN);
std::string bundleName(name);
eventInfo.SetBundleName(bundleName);
position += LEN;
return position;
}
bool RegisterElementOperatorFuzzTest(const uint8_t* data, size_t size)
{
if (data == nullptr || size < DATA_MIN_SIZE) {
return false;
}
auto instance = AccessibilitySystemAbilityClient::GetInstance();
if (!instance) {
return false;
}
size_t position = 0;
int32_t windowId = 0;
position += GetObject<int32_t>(windowId, &data[position], size - position);
std::shared_ptr<ElementOperatorForFuzzTest> elementOperator = std::make_shared<ElementOperatorForFuzzTest>();
instance->RegisterElementOperator(windowId, elementOperator);
position += GetObject<int32_t>(windowId, &data[position], size - position);
instance->DeregisterElementOperator(windowId);
return true;
}
bool GetAbilityListFuzzTest(const uint8_t* data, size_t size)
{
if (data == nullptr || size < DATA_MIN_SIZE) {
return false;
}
auto instance = AccessibilitySystemAbilityClient::GetInstance();
if (!instance) {
return false;
}
size_t position = 0;
uint32_t abilityTypes = 0;
position += GetObject<uint32_t>(abilityTypes, &data[position], size - position);
AbilityStateType stateType;
position += GetObject<AbilityStateType>(stateType, &data[position], size - position);
std::vector<AccessibilityAbilityInfo> infos;
instance->GetAbilityList(abilityTypes, stateType, infos);
return true;
}
bool SendEventFuzzTest(const uint8_t* data, size_t size)
{
if (data == nullptr || size < DATA_MIN_SIZE) {
return false;
}
auto instance = AccessibilitySystemAbilityClient::GetInstance();
if (!instance) {
return false;
}
size_t position = 0;
EventType eventType;
position += GetObject<EventType>(eventType, &data[position], size - position);
int32_t componentId = 0;
position += GetObject<int32_t>(componentId, &data[position], size - position);
instance->SendEvent(eventType, componentId);
AccessibilityEventInfo eventInfo;
(void)CreateEventInfo(eventInfo, data, size - position);
instance->SendEvent(eventInfo);
return true;
}
bool SubscribeStateObserverFuzzTest(const uint8_t* data, size_t size)
{
if (data == nullptr || size < DATA_MIN_SIZE) {
return false;
}
auto instance = AccessibilitySystemAbilityClient::GetInstance();
if (!instance) {
return false;
}
size_t position = 0;
uint32_t eventTypes = 0;
position += GetObject<uint32_t>(eventTypes, &data[position], size - position);
std::shared_ptr<StateObserverForFuzzTest> observer = std::make_shared<StateObserverForFuzzTest>();
instance->SubscribeStateObserver(observer, eventTypes);
position += GetObject<uint32_t>(eventTypes, &data[position], size - position);
instance->UnsubscribeStateObserver(observer, eventTypes);
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::RegisterElementOperatorFuzzTest(data, size);
OHOS::Accessibility::GetAbilityListFuzzTest(data, size);
OHOS::Accessibility::SendEventFuzzTest(data, size);
OHOS::Accessibility::SubscribeStateObserverFuzzTest(data, size);
return 0;
}

View File

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

View File

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

View File

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

View File

@ -0,0 +1,43 @@
# Copyright (c) 2021 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("AccessibleAbilityClientFuzzTest") {
module_out_path = "accessibility/aafwk"
fuzz_config_file = "../../fuzztest/accessibleabilityclient_fuzzer"
include_dirs = []
cflags = [
"-g",
"-O0",
"-Wno-unused-variable",
"-fno-omit-frame-pointer",
]
sources = [ "accessibleabilityclient_fuzzer.cpp" ]
deps = [ "//base/accessibility/interfaces/innerkits/aafwk:accessibleability" ]
}
###############################################################################
group("fuzztest") {
testonly = true
deps = []
deps += [
# deps file
":AccessibleAbilityClientFuzzTest",
]
}
###############################################################################

View File

@ -0,0 +1,601 @@
/*
* 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 "accessibleabilityclient_fuzzer.h"
#include "accessibility_element_info.h"
#include "accessibility_ui_test_ability.h"
namespace OHOS {
namespace {
constexpr size_t DATA_MIN_SIZE = 416;
constexpr char END_CHAR = '\0';
constexpr size_t LEN = 10;
constexpr size_t VEC_SIZE = 5;
constexpr size_t MAP_SIZE = 5;
} // namespace
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;
}
std::memcpy(&object, data, objectSize);
return objectSize;
}
static size_t GenerateRect(OHOS::Accessibility::Rect &bounds, const uint8_t* data, size_t size)
{
size_t position = 0;
int32_t posX = 0;
int32_t posY = 0;
position += GetObject<int32_t>(posX, &data[position], size - position);
position += GetObject<int32_t>(posY, &data[position], size - position);
bounds.SetLeftTopScreenPostion(posX, posY);
position += GetObject<int32_t>(posX, &data[position], size - position);
position += GetObject<int32_t>(posY, &data[position], size - position);
bounds.SetRightBottomScreenPostion(posX, posY);
return position;
}
static size_t GenerateRangeInfo(OHOS::Accessibility::RangeInfo &rangeInfo, const uint8_t* data, size_t size)
{
size_t position = 0;
int32_t int32Data = 0;
position += GetObject<int32_t>(int32Data, &data[position], size - position);
rangeInfo.SetMin(int32Data);
position += GetObject<int32_t>(int32Data, &data[position], size - position);
rangeInfo.SetMax(int32Data);
position += GetObject<int32_t>(int32Data, &data[position], size - position);
rangeInfo.SetCurrent(int32Data);
return position;
}
static size_t GenerateGridInfo(OHOS::Accessibility::GridInfo &grid, const uint8_t* data, size_t size)
{
size_t position = 0;
int32_t rowCount = 0;
int32_t columnCount = 0;
int32_t selectionMode = 0;
position += GetObject<int32_t>(rowCount, &data[position], size - position);
position += GetObject<int32_t>(columnCount, &data[position], size - position);
position += GetObject<int32_t>(selectionMode, &data[position], size - position);
grid.SetGrid(rowCount, columnCount, selectionMode);
return position;
}
static size_t GenerateGridItemInfo(OHOS::Accessibility::GridItemInfo &gridItem, const uint8_t* data, size_t size)
{
size_t position = 0;
int32_t columnIndex_ = 0;
int32_t rowIndex = 0;
int32_t columnSpan = 0;
int32_t rowSpan = 0;
position += GetObject<int32_t>(columnIndex_, &data[position], size - position);
position += GetObject<int32_t>(rowIndex, &data[position], size - position);
position += GetObject<int32_t>(columnSpan, &data[position], size - position);
position += GetObject<int32_t>(rowSpan, &data[position], size - position);
bool heading = data[position++] & 0x01;
bool selected = data[position++] & 0x01;
gridItem.SetGridItemInfo(rowIndex, rowSpan, columnIndex_, columnSpan, heading, selected);
return position;
}
static size_t GenerateAccessibilityElementInfo(OHOS::Accessibility::AccessibilityElementInfo &sourceElementInfo,
const uint8_t* data, size_t size)
{
size_t position = 0;
int32_t int32Data = 0;
position += GetObject<int32_t>(int32Data, &data[position], size - position);
sourceElementInfo.SetWindowId(int32Data);
position += GetObject<int32_t>(int32Data, &data[position], size - position);
sourceElementInfo.SetAccessibilityId(int32Data);
position += GetObject<int32_t>(int32Data, &data[position], size - position);
sourceElementInfo.SetParent(int32Data);
position += GetObject<int32_t>(int32Data, &data[position], size - position);
sourceElementInfo.SetTextLengthLimit(int32Data);
position += GetObject<int32_t>(int32Data, &data[position], size - position);
sourceElementInfo.SetChannelId(int32Data);
position += GetObject<int32_t>(int32Data, &data[position], size - position);
sourceElementInfo.SetCurrentIndex(int32Data);
position += GetObject<int32_t>(int32Data, &data[position], size - position);
sourceElementInfo.SetBeginIndex(int32Data);
position += GetObject<int32_t>(int32Data, &data[position], size - position);
sourceElementInfo.SetEndIndex(int32Data);
position += GetObject<int32_t>(int32Data, &data[position], size - position);
sourceElementInfo.SetLiveRegion(int32Data);
position += GetObject<int32_t>(int32Data, &data[position], size - position);
sourceElementInfo.SetLabeled(int32Data);
position += GetObject<int32_t>(int32Data, &data[position], size - position);
sourceElementInfo.SetSelectedBegin(int32Data);
position += GetObject<int32_t>(int32Data, &data[position], size - position);
sourceElementInfo.SetSelectedEnd(int32Data);
position += GetObject<int32_t>(int32Data, &data[position], size - position);
sourceElementInfo.SetInputType(int32Data);
for (size_t i = 0; i < VEC_SIZE; i++) {
position += GetObject<int32_t>(int32Data, &data[position], size - position);
sourceElementInfo.AddChild(int32Data);
}
char name[LEN + 1];
name[LEN] = END_CHAR;
std::memcpy(&name, &data[position], LEN);
std::string bundleName(name);
sourceElementInfo.SetBundleName(bundleName);
position += LEN;
std::memcpy(&name, &data[position], LEN);
std::string componentType(name);
sourceElementInfo.SetComponentType(componentType);
position += LEN;
std::memcpy(&name, &data[position], LEN);
std::string text(name);
sourceElementInfo.SetContent(text);
position += LEN;
std::memcpy(&name, &data[position], LEN);
std::string hintText(name);
sourceElementInfo.SetHint(hintText);
position += LEN;
std::memcpy(&name, &data[position], LEN);
std::string contentDescription(name);
sourceElementInfo.SetDescriptionInfo(contentDescription);
position += LEN;
std::memcpy(&name, &data[position], LEN);
std::string resourceName(name);
sourceElementInfo.SetComponentResourceId(resourceName);
position += LEN;
std::memcpy(&name, &data[position], LEN);
std::string inspectorKey(name);
sourceElementInfo.SetInspectorKey(inspectorKey);
position += LEN;
std::memcpy(&name, &data[position], LEN);
std::string error(name);
sourceElementInfo.SetError(error);
position += LEN;
sourceElementInfo.SetCheckable(data[position++] & 0x01);
sourceElementInfo.SetChecked(data[position++] & 0x01);
sourceElementInfo.SetFocusable(data[position++] & 0x01);
sourceElementInfo.SetFocused(data[position++] & 0x01);
sourceElementInfo.SetVisible(data[position++] & 0x01);
sourceElementInfo.SetAccessibilityFocus(data[position++] & 0x01);
sourceElementInfo.SetSelected(data[position++] & 0x01);
sourceElementInfo.SetClickable(data[position++] & 0x01);
sourceElementInfo.SetLongClickable(data[position++] & 0x01);
sourceElementInfo.SetEnabled(data[position++] & 0x01);
sourceElementInfo.SetPassword(data[position++] & 0x01);
sourceElementInfo.SetScrollable(data[position++] & 0x01);
sourceElementInfo.SetEditable(data[position++] & 0x01);
sourceElementInfo.SetPopupSupported(data[position++] & 0x01);
sourceElementInfo.SetPluraLineSupported(data[position++] & 0x01);
sourceElementInfo.SetDeletable(data[position++] & 0x01);
sourceElementInfo.SetHinting(data[position++] & 0x01);
sourceElementInfo.SetEssential(data[position++] & 0x01);
sourceElementInfo.SetContentInvalid(data[position++] & 0x01);
sourceElementInfo.SetValidElement(data[position++] & 0x01);
OHOS::Accessibility::Rect bounds;
position += GenerateRect(bounds, &data[position], size - position);
sourceElementInfo.SetRectInScreen(bounds);
OHOS::Accessibility::RangeInfo rangeInfo;
position += GenerateRangeInfo(rangeInfo, &data[position], size - position);
sourceElementInfo.SetRange(rangeInfo);
OHOS::Accessibility::GridInfo grid;
position += GenerateGridInfo(grid, &data[position], size - position);
sourceElementInfo.SetGrid(grid);
OHOS::Accessibility::GridItemInfo gridItem;
position += GenerateGridItemInfo(gridItem, &data[position], size - position);
sourceElementInfo.SetGridItem(gridItem);
for (size_t i = 0; i < VEC_SIZE; i++) {
position += GetObject<int32_t>(int32Data, &data[position], size - position);
std::memcpy(&name, &data[position], LEN);
position += LEN;
std::string description(name);
OHOS::Accessibility::AccessibleAction action(
static_cast<OHOS::Accessibility::ActionType>(int32Data), description);
sourceElementInfo.AddAction(action);
}
return position;
}
static size_t GenerateAccessibilityWindowInfo(OHOS::Accessibility::AccessibilityWindowInfo &sourceWindowInfo,
const uint8_t* data, size_t size)
{
size_t position = 0;
uint64_t uint64Data = 0;
position += GetObject<uint64_t>(uint64Data, &data[position], size - position);
sourceWindowInfo.SetDisplayId(uint64Data);
int32_t int32Data = 0;
position += GetObject<int32_t>(int32Data, &data[position], size - position);
sourceWindowInfo.SetWindowLayer(int32Data);
position += GetObject<int32_t>(int32Data, &data[position], size - position);
sourceWindowInfo.SetWindowId(int32Data);
position += GetObject<int32_t>(int32Data, &data[position], size - position);
sourceWindowInfo.SetAnchorId(int32Data);
position += GetObject<int32_t>(int32Data, &data[position], size - position);
sourceWindowInfo.SetChannelId(int32Data);
sourceWindowInfo.SetActive(data[position++] & 0x01);
sourceWindowInfo.SetFocused(data[position++] & 0x01);
sourceWindowInfo.SetAccessibilityFocused(data[position++] & 0x01);
OHOS::Accessibility::Rect bounds;
position += GenerateRect(bounds, &data[position], size - position);
sourceWindowInfo.SetRectInScreen(bounds);
return position;
}
static size_t GenerateAccessibilityEventInfoPartial(OHOS::Accessibility::AccessibilityEventInfo &sourceEventInfo,
const uint8_t* data, size_t size)
{
size_t position = 0;
uint32_t uint32Data = 0;
position += GetObject<uint32_t>(uint32Data, &data[position], size - position);
sourceEventInfo.SetEventType(static_cast<OHOS::Accessibility::EventType>(uint32Data));
position += GetObject<uint32_t>(uint32Data, &data[position], size - position);
sourceEventInfo.SetGestureType(static_cast<OHOS::Accessibility::GestureType>(uint32Data));
char name[LEN + 1];
name[LEN] = END_CHAR;
std::memcpy(&name, &data[position], LEN);
std::string bundleName(name);
sourceEventInfo.SetBundleName(bundleName);
position += LEN;
int32_t int32Data = 0;
position += GetObject<int32_t>(int32Data, &data[position], size - position);
sourceEventInfo.SetTriggerAction(static_cast<OHOS::Accessibility::ActionType>(int32Data));
position += GetObject<int32_t>(int32Data, &data[position], size - position);
sourceEventInfo.SetTextMovementStep(static_cast<OHOS::Accessibility::TextMoveUnit>(int32Data));
position += GetObject<int32_t>(int32Data, &data[position], size - position);
sourceEventInfo.SetWindowContentChangeTypes(
static_cast<OHOS::Accessibility::WindowsContentChangeTypes>(int32Data));
position += GetObject<int32_t>(int32Data, &data[position], size - position);
sourceEventInfo.SetWindowChangeTypes(static_cast<OHOS::Accessibility::WindowUpdateType>(int32Data));
position += GetObject<int32_t>(int32Data, &data[position], size - position);
sourceEventInfo.SetRecordCount(int32Data);
position += GetObject<int32_t>(int32Data, &data[position], size - position);
sourceEventInfo.SetNotificationInfo(static_cast<OHOS::Accessibility::NotificationCategory>(int32Data));
position += GetObject<int32_t>(int32Data, &data[position], size - position);
sourceEventInfo.SetPageId(int32Data);
int64_t int64Data = 0;
position += GetObject<int64_t>(int64Data, &data[position], size - position);
sourceEventInfo.SetTimeStamp(int64Data);
return position;
}
static size_t GenerateAccessibilityEventInfo(OHOS::Accessibility::AccessibilityEventInfo &sourceEventInfo,
const uint8_t* data, size_t size)
{
size_t position = 0;
position += GenerateAccessibilityEventInfoPartial(sourceEventInfo, &data[position], size - position);
for (size_t i = 0; i < VEC_SIZE; i++) {
OHOS::Accessibility::AccessibilityEventInfo record;
position += GenerateAccessibilityEventInfoPartial(record, &data[position], size - position);
sourceEventInfo.AddRecord(record);
}
return position;
}
bool DoSomethingInterestingWithGetFocus(const uint8_t* data, size_t size)
{
if (data == nullptr || size < DATA_MIN_SIZE) {
return false;
}
size_t startPos = 0;
int32_t focusType = 0;
OHOS::Accessibility::AccessibilityElementInfo resultElementInfo;
startPos += GetObject<int32_t>(focusType, &data[startPos], size - startPos);
OHOS::Accessibility::AccessibilityUITestAbility::GetInstance()->GetFocus(focusType, resultElementInfo);
return true;
}
bool DoSomethingInterestingWithGetFocusByElementInfo(const uint8_t* data, size_t size)
{
if (data == nullptr || size < DATA_MIN_SIZE) {
return false;
}
size_t startPos = 0;
int32_t focusType = 0;
OHOS::Accessibility::AccessibilityElementInfo sourceElementInfo;
OHOS::Accessibility::AccessibilityElementInfo resultElementInfo;
startPos += GetObject<int32_t>(focusType, &data[startPos], size - startPos);
startPos += GenerateAccessibilityElementInfo(sourceElementInfo, &data[startPos], size - startPos);
OHOS::Accessibility::AccessibilityUITestAbility::GetInstance()->GetFocusByElementInfo(
sourceElementInfo, focusType, resultElementInfo);
return true;
}
bool DoSomethingInterestingWithGetRootByWindow(const uint8_t* data, size_t size)
{
if (data == nullptr || size < DATA_MIN_SIZE) {
return false;
}
size_t startPos = 0;
OHOS::Accessibility::AccessibilityWindowInfo sourceWindowInfo;
OHOS::Accessibility::AccessibilityElementInfo resultElementInfo;
startPos += GenerateAccessibilityWindowInfo(sourceWindowInfo, &data[startPos], size - startPos);
OHOS::Accessibility::AccessibilityUITestAbility::GetInstance()->GetRootByWindow(
sourceWindowInfo, resultElementInfo);
return true;
}
bool DoSomethingInterestingWithGetWindows(const uint8_t* data, size_t size)
{
if (data == nullptr || size < DATA_MIN_SIZE) {
return false;
}
size_t startPos = 0;
uint64_t displayId = 0;
std::vector<OHOS::Accessibility::AccessibilityWindowInfo> resultWindowInfos;
startPos += GetObject<uint64_t>(displayId, &data[startPos], size - startPos);
OHOS::Accessibility::AccessibilityUITestAbility::GetInstance()->GetWindows(displayId, resultWindowInfos);
return true;
}
bool DoSomethingInterestingWithExecuteCommonAction(const uint8_t* data, size_t size)
{
if (data == nullptr || size < DATA_MIN_SIZE) {
return false;
}
size_t startPos = 0;
uint32_t commonAction = 0;
startPos += GetObject<uint32_t>(commonAction, &data[startPos], size - startPos);
OHOS::Accessibility::AccessibilityUITestAbility::GetInstance()->ExecuteCommonAction(
static_cast<OHOS::Accessibility::GlobalAction>(commonAction));
return true;
}
bool DoSomethingInterestingWithGetNext(const uint8_t* data, size_t size)
{
if (data == nullptr || size < DATA_MIN_SIZE) {
return false;
}
size_t startPos = 0;
int32_t direction = 0;
OHOS::Accessibility::AccessibilityElementInfo sourceElementInfo;
OHOS::Accessibility::AccessibilityElementInfo resultElementInfo;
startPos += GetObject<int32_t>(direction, &data[startPos], size - startPos);
startPos += GenerateAccessibilityElementInfo(sourceElementInfo, &data[startPos], size - startPos);
OHOS::Accessibility::AccessibilityUITestAbility::GetInstance()->GetNext(sourceElementInfo,
static_cast<OHOS::Accessibility::FocusMoveDirection>(direction), resultElementInfo);
return true;
}
bool DoSomethingInterestingWithGetChildElementInfo(const uint8_t* data, size_t size)
{
if (data == nullptr || size < DATA_MIN_SIZE) {
return false;
}
size_t startPos = 0;
int32_t index = 0;
OHOS::Accessibility::AccessibilityElementInfo sourceElementInfo;
OHOS::Accessibility::AccessibilityElementInfo resultElementInfo;
startPos += GetObject<int32_t>(index, &data[startPos], size - startPos);
startPos += GenerateAccessibilityElementInfo(sourceElementInfo, &data[startPos], size - startPos);
OHOS::Accessibility::AccessibilityUITestAbility::GetInstance()->GetChildElementInfo(
index, sourceElementInfo, resultElementInfo);
return true;
}
bool DoSomethingInterestingWithGetByContent(const uint8_t* data, size_t size)
{
if (data == nullptr || size < DATA_MIN_SIZE) {
return false;
}
size_t startPos = 0;
OHOS::Accessibility::AccessibilityElementInfo sourceElementInfo;
std::vector<OHOS::Accessibility::AccessibilityElementInfo> resultElementInfos;
startPos += GenerateAccessibilityElementInfo(sourceElementInfo, &data[startPos], size - startPos);
char name[LEN + 1];
name[LEN] = END_CHAR;
std::memcpy(&name, &data[startPos], LEN);
std::string text(name);
startPos += LEN;
OHOS::Accessibility::AccessibilityUITestAbility::GetInstance()->GetByContent(
sourceElementInfo, text, resultElementInfos);
return true;
}
bool DoSomethingInterestingWithGetAnchor(const uint8_t* data, size_t size)
{
if (data == nullptr || size < DATA_MIN_SIZE) {
return false;
}
size_t startPos = 0;
OHOS::Accessibility::AccessibilityWindowInfo sourceWindowInfo;
OHOS::Accessibility::AccessibilityElementInfo resultElementInfo;
startPos += GenerateAccessibilityWindowInfo(sourceWindowInfo, &data[startPos], size - startPos);
OHOS::Accessibility::AccessibilityUITestAbility::GetInstance()->GetAnchor(sourceWindowInfo, resultElementInfo);
return true;
}
bool DoSomethingInterestingWithGetSource(const uint8_t* data, size_t size)
{
if (data == nullptr || size < DATA_MIN_SIZE) {
return false;
}
size_t startPos = 0;
OHOS::Accessibility::AccessibilityEventInfo sourceEventInfo;
OHOS::Accessibility::AccessibilityElementInfo resultElementInfo;
startPos += GenerateAccessibilityEventInfo(sourceEventInfo, &data[startPos], size - startPos);
OHOS::Accessibility::AccessibilityUITestAbility::GetInstance()->GetSource(sourceEventInfo, resultElementInfo);
return true;
}
bool DoSomethingInterestingWithGetParentElementInfo(const uint8_t* data, size_t size)
{
if (data == nullptr || size < DATA_MIN_SIZE) {
return false;
}
size_t startPos = 0;
OHOS::Accessibility::AccessibilityElementInfo sourceElementInfo;
OHOS::Accessibility::AccessibilityElementInfo resultElementInfo;
startPos += GenerateAccessibilityElementInfo(sourceElementInfo, &data[startPos], size - startPos);
OHOS::Accessibility::AccessibilityUITestAbility::GetInstance()->GetParentElementInfo(
sourceElementInfo, resultElementInfo);
return true;
}
bool DoSomethingInterestingWithExecuteAction(const uint8_t* data, size_t size)
{
if (data == nullptr || size < DATA_MIN_SIZE) {
return false;
}
size_t startPos = 0;
OHOS::Accessibility::AccessibilityElementInfo sourceElementInfo;
startPos += GenerateAccessibilityElementInfo(sourceElementInfo, &data[startPos], size - startPos);
int32_t action = 0;
startPos += GetObject<int32_t>(action, &data[startPos], size - startPos);
std::map<std::string, std::string> actionArguments;
for (size_t i = 0; i < MAP_SIZE; i++) {
char name[LEN + 1];
name[LEN] = END_CHAR;
std::memcpy(&name, &data[startPos], LEN);
std::string action1(name);
startPos += LEN;
std::memcpy(&name, &data[startPos], LEN);
std::string action2(name);
startPos += LEN;
actionArguments.insert(std::make_pair(action1, action2));
}
OHOS::Accessibility::AccessibilityUITestAbility::GetInstance()->ExecuteAction(
sourceElementInfo, static_cast<OHOS::Accessibility::ActionType>(action), actionArguments);
return true;
}
bool DoSomethingInterestingWithSetEventTypeFilter(const uint8_t* data, size_t size)
{
if (data == nullptr || size < DATA_MIN_SIZE) {
return false;
}
size_t startPos = 0;
uint32_t filter = 0;
startPos += GetObject<uint32_t>(filter, &data[startPos], size - startPos);
OHOS::Accessibility::AccessibilityUITestAbility::GetInstance()->SetEventTypeFilter(filter);
return true;
}
bool DoSomethingInterestingWithSetTargetBundleName(const uint8_t* data, size_t size)
{
if (data == nullptr || size < DATA_MIN_SIZE) {
return false;
}
size_t startPos = 0;
std::vector<std::string> targetBundleNames;
for (size_t i = 0; i < VEC_SIZE; i++) {
char name[LEN + 1];
name[LEN] = END_CHAR;
std::memcpy(&name, &data[startPos], LEN);
std::string targetBundleName(name);
startPos += LEN;
targetBundleNames.push_back(targetBundleName);
}
OHOS::Accessibility::AccessibilityUITestAbility::GetInstance()->SetTargetBundleName(targetBundleNames);
return true;
}
} // namespace OHOS
/* Fuzzer entry point */
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
{
/* Run your code on data */
OHOS::DoSomethingInterestingWithGetFocus(data, size);
OHOS::DoSomethingInterestingWithGetFocusByElementInfo(data, size);
OHOS::DoSomethingInterestingWithGetRootByWindow(data, size);
OHOS::DoSomethingInterestingWithGetWindows(data, size);
OHOS::DoSomethingInterestingWithExecuteCommonAction(data, size);
OHOS::DoSomethingInterestingWithGetNext(data, size);
OHOS::DoSomethingInterestingWithGetChildElementInfo(data, size);
OHOS::DoSomethingInterestingWithGetByContent(data, size);
OHOS::DoSomethingInterestingWithGetAnchor(data, size);
OHOS::DoSomethingInterestingWithGetSource(data, size);
OHOS::DoSomethingInterestingWithGetParentElementInfo(data, size);
OHOS::DoSomethingInterestingWithExecuteAction(data, size);
OHOS::DoSomethingInterestingWithSetEventTypeFilter(data, size);
OHOS::DoSomethingInterestingWithSetTargetBundleName(data, size);
return 0;
}

View File

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

View File

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

View File

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