fix window manager fuzz test

Signed-off-by: wangjian10 <wangjian10@huawei.com>
This commit is contained in:
wangjian10 2024-05-06 18:58:53 +08:00
parent f5f2e208c6
commit 43a225bca7

View File

@ -117,21 +117,31 @@ bool DoSomethingForWindowManagerImpl(WindowManager& windowManager, const uint8_t
void CheckAccessibilityWindowInfo(WindowManager& windowManager, const uint8_t* data, size_t size)
{
Parcel accessibilityWindowInfosParcel;
if (accessibilityWindowInfosParcel.WriteBuffer(data, size)) {
std::vector<sptr<AccessibilityWindowInfo>> windowInfos;
MarshallingHelper::UnmarshallingVectorParcelableObj<AccessibilityWindowInfo>(accessibilityWindowInfosParcel,
windowInfos);
windowManager.GetAccessibilityWindowInfo(windowInfos);
WindowUpdateType type;
GetObject<WindowUpdateType>(type, data, size);
windowManager.NotifyAccessibilityWindowInfo(windowInfos, type);
if (!accessibilityWindowInfosParcel.WriteBuffer(data, size)) {
return;
}
std::vector<sptr<AccessibilityWindowInfo>> windowInfos;
if (!MarshallingHelper::UnmarshallingVectorParcelableObj<AccessibilityWindowInfo>(
accessibilityWindowInfosParcel, windowInfos)) {
return;
}
windowManager.GetAccessibilityWindowInfo(windowInfos);
WindowUpdateType type;
GetObject<WindowUpdateType>(type, data, size);
windowManager.NotifyAccessibilityWindowInfo(windowInfos, type);
}
void CheckVisibilityInfo(WindowManager& windowManager, const uint8_t* data, size_t size)
{
Parcel windowVisibilityInfosParcel;
windowVisibilityInfosParcel.WriteBuffer(data, size);
if (!windowVisibilityInfosParcel.WriteBuffer(data, size)) {
return;
}
std::vector<sptr<WindowVisibilityInfo>> visibilitynfos;
MarshallingHelper::UnmarshallingVectorParcelableObj<WindowVisibilityInfo>(windowVisibilityInfosParcel,
visibilitynfos);
if (!MarshallingHelper::UnmarshallingVectorParcelableObj<WindowVisibilityInfo>(windowVisibilityInfosParcel,
visibilitynfos)) {
return;
}
windowManager.GetVisibilityWindowInfo(visibilitynfos);
windowManager.UpdateWindowVisibilityInfo(visibilitynfos);
bool enable = false;
@ -140,11 +150,9 @@ void CheckAccessibilityWindowInfo(WindowManager& windowManager, const uint8_t* d
bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size)
{
if (data == nullptr || size < DATA_MIN_SIZE) {
return false;
}
WindowManager& windowManager = WindowManager::GetInstance();
CheckAccessibilityWindowInfo(windowManager, data, size);
CheckVisibilityInfo(windowManager, data, size);
Parcel focusChangeInfoParcel;
if (focusChangeInfoParcel.WriteBuffer(data, size)) {
FocusChangeInfo::Unmarshalling(focusChangeInfoParcel);
@ -195,6 +203,9 @@ bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size)
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
{
/* Run your code on data */
if (data == nullptr || size < OHOS::DATA_MIN_SIZE) {
return 0;
}
OHOS::DoSomethingInterestingWithMyAPI(data, size);
return 0;
}