From 68cf11d6dda9d037f611f4e9b66d66a852db64fa Mon Sep 17 00:00:00 2001 From: mayunteng_1 Date: Fri, 28 Apr 2023 05:41:40 +0000 Subject: [PATCH] fuzz Signed-off-by: mayunteng_1 Change-Id: I4fe03ddc312d85677b95e6ae38ef1962ae58d401 --- test/fuzztest/BUILD.gn | 3 + test/fuzztest/getshadowoffset_fuzzer/BUILD.gn | 37 ++++++++++ .../getshadowoffset_fuzzer/corpus/init | 14 ++++ .../getshadowoffset_fuzzer.cpp | 48 ++++++++++++ .../getshadowoffset_fuzzer.h | 21 ++++++ .../getshadowoffset_fuzzer/project.xml | 25 +++++++ .../setdragwindowvisible_fuzzer/BUILD.gn | 38 ++++++++++ .../setdragwindowvisible_fuzzer/corpus/init | 14 ++++ .../setdragwindowvisible_fuzzer/project.xml | 25 +++++++ .../setdragwindowvisible_fuzzer.cpp | 73 +++++++++++++++++++ .../setdragwindowvisible_fuzzer.h | 21 ++++++ test/fuzztest/updatedragstyle_fuzzer/BUILD.gn | 38 ++++++++++ .../updatedragstyle_fuzzer/corpus/init | 14 ++++ .../updatedragstyle_fuzzer/project.xml | 25 +++++++ .../updatedragstyle_fuzzer.cpp | 69 ++++++++++++++++++ .../updatedragstyle_fuzzer.h | 21 ++++++ 16 files changed, 486 insertions(+) create mode 100644 test/fuzztest/getshadowoffset_fuzzer/BUILD.gn create mode 100644 test/fuzztest/getshadowoffset_fuzzer/corpus/init create mode 100644 test/fuzztest/getshadowoffset_fuzzer/getshadowoffset_fuzzer.cpp create mode 100644 test/fuzztest/getshadowoffset_fuzzer/getshadowoffset_fuzzer.h create mode 100644 test/fuzztest/getshadowoffset_fuzzer/project.xml create mode 100644 test/fuzztest/setdragwindowvisible_fuzzer/BUILD.gn create mode 100644 test/fuzztest/setdragwindowvisible_fuzzer/corpus/init create mode 100644 test/fuzztest/setdragwindowvisible_fuzzer/project.xml create mode 100644 test/fuzztest/setdragwindowvisible_fuzzer/setdragwindowvisible_fuzzer.cpp create mode 100644 test/fuzztest/setdragwindowvisible_fuzzer/setdragwindowvisible_fuzzer.h create mode 100644 test/fuzztest/updatedragstyle_fuzzer/BUILD.gn create mode 100644 test/fuzztest/updatedragstyle_fuzzer/corpus/init create mode 100644 test/fuzztest/updatedragstyle_fuzzer/project.xml create mode 100644 test/fuzztest/updatedragstyle_fuzzer/updatedragstyle_fuzzer.cpp create mode 100644 test/fuzztest/updatedragstyle_fuzzer/updatedragstyle_fuzzer.h diff --git a/test/fuzztest/BUILD.gn b/test/fuzztest/BUILD.gn index 9b1b7bc3b..bdf35141d 100644 --- a/test/fuzztest/BUILD.gn +++ b/test/fuzztest/BUILD.gn @@ -22,9 +22,12 @@ group("device_status_fuzztest") { "devicestatusagent_fuzzer:fuzztest", "devicestatusclient_fuzzer:fuzztest", "getdragtargetpid_fuzzer:fuzztest", + "getshadowoffset_fuzzer:fuzztest", "getudkey_fuzzer:fuzztest", + "setdragwindowvisible_fuzzer:fuzztest", "startdrag_fuzzer:fuzztest", "stopdrag_fuzzer:fuzztest", + "updatedragstyle_fuzzer:fuzztest", ] if (fusion_interaction_coordination) { deps += [ diff --git a/test/fuzztest/getshadowoffset_fuzzer/BUILD.gn b/test/fuzztest/getshadowoffset_fuzzer/BUILD.gn new file mode 100644 index 000000000..9a1126483 --- /dev/null +++ b/test/fuzztest/getshadowoffset_fuzzer/BUILD.gn @@ -0,0 +1,37 @@ +# Copyright (c) 2023 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("//base/msdp/device_status/device_status.gni") +import("//build/config/features.gni") +import("//build/test.gni") +module_output_path = "device_status/device_status_native" + +ohos_fuzztest("GetShadowOffsetFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = "../../../test/fuzztest/getshadowoffset_fuzzer" + include_dirs = [ + "../../../interfaces/innerkits/interaction/include", + "../../../utils/common/include", + ] + sources = [ "getshadowoffset_fuzzer.cpp" ] + deps = [ "../../../interfaces/innerkits:devicestatus_client" ] + external_deps = [ + "hiviewdfx_hilog_native:libhilog", + "multimedia_image_framework:image_native", + ] +} + +group("fuzztest") { + testonly = true + deps = [ ":GetShadowOffsetFuzzTest" ] +} diff --git a/test/fuzztest/getshadowoffset_fuzzer/corpus/init b/test/fuzztest/getshadowoffset_fuzzer/corpus/init new file mode 100644 index 000000000..e4ceac1bc --- /dev/null +++ b/test/fuzztest/getshadowoffset_fuzzer/corpus/init @@ -0,0 +1,14 @@ +# Copyright (c) 2023 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 \ No newline at end of file diff --git a/test/fuzztest/getshadowoffset_fuzzer/getshadowoffset_fuzzer.cpp b/test/fuzztest/getshadowoffset_fuzzer/getshadowoffset_fuzzer.cpp new file mode 100644 index 000000000..d8d8adba5 --- /dev/null +++ b/test/fuzztest/getshadowoffset_fuzzer/getshadowoffset_fuzzer.cpp @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2023 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 "getshadowoffset_fuzzer.h" + +#include "fi_log.h" +#include "interaction_manager.h" + +namespace OHOS { +namespace Msdp { +namespace DeviceStatus { +namespace { +constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, MSDP_DOMAIN_ID, "GetShadowOffsetFuzzTest" }; +} // namespace + +void GetShadowOffsetFuzzTest() +{ + CALL_DEBUG_ENTER; + int32_t offsetX = 0; + int32_t offsetY = 0; + int32_t width = 0; + int32_t height = 0; + InteractionManager::GetInstance()->GetShadowOffset(offsetX, offsetY, width, height); + FI_HILOGD("offsetX:%{public}d,offsetY:%{public}d,width:%{public}d,height:%{public}d", + offsetX, offsetY, width, height); + return; +} +} // namespace DeviceStatus +} // namespace Msdp +} // namespace OHOS + +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + OHOS::Msdp::DeviceStatus::GetShadowOffsetFuzzTest(); + return 0; +} \ No newline at end of file diff --git a/test/fuzztest/getshadowoffset_fuzzer/getshadowoffset_fuzzer.h b/test/fuzztest/getshadowoffset_fuzzer/getshadowoffset_fuzzer.h new file mode 100644 index 000000000..2253f4982 --- /dev/null +++ b/test/fuzztest/getshadowoffset_fuzzer/getshadowoffset_fuzzer.h @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2023 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 GETSHADOWOFFSET_FUZZER_H +#define GETSHADOWOFFSET_FUZZER_H + +#define FUZZ_PROJECT_NAME "getshadowoffset_fuzzer" + +#endif // GETSHADOWOFFSET_FUZZER_H \ No newline at end of file diff --git a/test/fuzztest/getshadowoffset_fuzzer/project.xml b/test/fuzztest/getshadowoffset_fuzzer/project.xml new file mode 100644 index 000000000..bac4974e9 --- /dev/null +++ b/test/fuzztest/getshadowoffset_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + \ No newline at end of file diff --git a/test/fuzztest/setdragwindowvisible_fuzzer/BUILD.gn b/test/fuzztest/setdragwindowvisible_fuzzer/BUILD.gn new file mode 100644 index 000000000..eab528a56 --- /dev/null +++ b/test/fuzztest/setdragwindowvisible_fuzzer/BUILD.gn @@ -0,0 +1,38 @@ +# Copyright (c) 2023 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("//base/msdp/device_status/device_status.gni") +import("//build/config/features.gni") +import("//build/test.gni") +module_output_path = "device_status/device_status_native" + +ohos_fuzztest("SetDragWindowVisibleFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = "../../../test/fuzztest/setdragwindowvisible_fuzzer" + include_dirs = [ + "../../../interfaces/innerkits/interaction/include", + "../../../utils/common/include", + ] + sources = [ "setdragwindowvisible_fuzzer.cpp" ] + deps = [ "../../../interfaces/innerkits:devicestatus_client" ] + external_deps = [ + "c_utils:utils", + "hiviewdfx_hilog_native:libhilog", + "multimedia_image_framework:image_native", + ] +} + +group("fuzztest") { + testonly = true + deps = [ ":SetDragWindowVisibleFuzzTest" ] +} diff --git a/test/fuzztest/setdragwindowvisible_fuzzer/corpus/init b/test/fuzztest/setdragwindowvisible_fuzzer/corpus/init new file mode 100644 index 000000000..e4ceac1bc --- /dev/null +++ b/test/fuzztest/setdragwindowvisible_fuzzer/corpus/init @@ -0,0 +1,14 @@ +# Copyright (c) 2023 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 \ No newline at end of file diff --git a/test/fuzztest/setdragwindowvisible_fuzzer/project.xml b/test/fuzztest/setdragwindowvisible_fuzzer/project.xml new file mode 100644 index 000000000..bac4974e9 --- /dev/null +++ b/test/fuzztest/setdragwindowvisible_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + \ No newline at end of file diff --git a/test/fuzztest/setdragwindowvisible_fuzzer/setdragwindowvisible_fuzzer.cpp b/test/fuzztest/setdragwindowvisible_fuzzer/setdragwindowvisible_fuzzer.cpp new file mode 100644 index 000000000..4e1c427ff --- /dev/null +++ b/test/fuzztest/setdragwindowvisible_fuzzer/setdragwindowvisible_fuzzer.cpp @@ -0,0 +1,73 @@ +/* + * Copyright (c) 2023 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 "setdragwindowvisible_fuzzer.h" + +#include "securec.h" + +#include "devicestatus_define.h" +#include "fi_log.h" +#include "interaction_manager.h" + +namespace OHOS { +namespace Msdp { +namespace DeviceStatus { +namespace { +constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, MSDP_DOMAIN_ID, "SetDragWindowVisibleFuzzTest" }; +constexpr int32_t NUM_TWO = 2; +} // namespace + +template +void GetObject(const uint8_t *data, size_t size, T &object) +{ + size_t objectSize = sizeof(object); + if (objectSize > size) { + return; + } + errno_t ret = memcpy_s(&object, objectSize, data, objectSize); + if (ret != RET_OK) { + return; + } + return; +} + +void SetDragWindowVisibleFuzzTest(const uint8_t* data, size_t size) +{ + CALL_DEBUG_ENTER; + bool bWindowVisible = false; + int32_t num = 0; + GetObject(data, size, num); + if ((num % NUM_TWO) == 1) { + bWindowVisible = true; + } + int32_t ret = InteractionManager::GetInstance()->SetDragWindowVisible(bWindowVisible); + FI_HILOGD("ret:%{public}d", ret); + return; +} +} // namespace DeviceStatus +} // namespace Msdp +} // namespace OHOS + +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + if (data == nullptr) { + return 0; + } + if (size < sizeof(int32_t)) { + return 0; + } + OHOS::Msdp::DeviceStatus::SetDragWindowVisibleFuzzTest(data, size); + return 0; +} \ No newline at end of file diff --git a/test/fuzztest/setdragwindowvisible_fuzzer/setdragwindowvisible_fuzzer.h b/test/fuzztest/setdragwindowvisible_fuzzer/setdragwindowvisible_fuzzer.h new file mode 100644 index 000000000..411f9ecfb --- /dev/null +++ b/test/fuzztest/setdragwindowvisible_fuzzer/setdragwindowvisible_fuzzer.h @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2023 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 SETDRAGWINDOWVISIBLE_FUZZER_H +#define SETDRAGWINDOWVISIBLE_FUZZER_H + +#define FUZZ_PROJECT_NAME "setdragwindowvisible_fuzzer" + +#endif // SETDRAGWINDOWVISIBLE_FUZZER_H \ No newline at end of file diff --git a/test/fuzztest/updatedragstyle_fuzzer/BUILD.gn b/test/fuzztest/updatedragstyle_fuzzer/BUILD.gn new file mode 100644 index 000000000..f8e0ee5ab --- /dev/null +++ b/test/fuzztest/updatedragstyle_fuzzer/BUILD.gn @@ -0,0 +1,38 @@ +# Copyright (c) 2023 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("//base/msdp/device_status/device_status.gni") +import("//build/config/features.gni") +import("//build/test.gni") +module_output_path = "device_status/device_status_native" + +ohos_fuzztest("UpdateDragStyleFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = "../../../test/fuzztest/updatedragstyle_fuzzer" + include_dirs = [ + "../../../interfaces/innerkits/interaction/include", + "../../../utils/common/include", + ] + sources = [ "updatedragstyle_fuzzer.cpp" ] + deps = [ "../../../interfaces/innerkits:devicestatus_client" ] + external_deps = [ + "c_utils:utils", + "hiviewdfx_hilog_native:libhilog", + "multimedia_image_framework:image_native", + ] +} + +group("fuzztest") { + testonly = true + deps = [ ":UpdateDragStyleFuzzTest" ] +} diff --git a/test/fuzztest/updatedragstyle_fuzzer/corpus/init b/test/fuzztest/updatedragstyle_fuzzer/corpus/init new file mode 100644 index 000000000..e4ceac1bc --- /dev/null +++ b/test/fuzztest/updatedragstyle_fuzzer/corpus/init @@ -0,0 +1,14 @@ +# Copyright (c) 2023 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 \ No newline at end of file diff --git a/test/fuzztest/updatedragstyle_fuzzer/project.xml b/test/fuzztest/updatedragstyle_fuzzer/project.xml new file mode 100644 index 000000000..4fdbc407f --- /dev/null +++ b/test/fuzztest/updatedragstyle_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/updatedragstyle_fuzzer/updatedragstyle_fuzzer.cpp b/test/fuzztest/updatedragstyle_fuzzer/updatedragstyle_fuzzer.cpp new file mode 100644 index 000000000..82f30e976 --- /dev/null +++ b/test/fuzztest/updatedragstyle_fuzzer/updatedragstyle_fuzzer.cpp @@ -0,0 +1,69 @@ +/* + * Copyright (c) 2023 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 "updatedragstyle_fuzzer.h" + +#include "securec.h" + +#include "devicestatus_define.h" +#include "fi_log.h" +#include "interaction_manager.h" + +namespace OHOS { +namespace Msdp { +namespace DeviceStatus { +namespace { +constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, MSDP_DOMAIN_ID, "UpdateDragStyleFuzzTest" }; +constexpr int32_t DRAGCURSORSTYLE_MAX = 4; +} // namespace + +template +void GetObject(const uint8_t *data, size_t size, T &object) +{ + size_t objectSize = sizeof(object); + if (objectSize > size) { + return; + } + errno_t ret = memcpy_s(&object, objectSize, data, objectSize); + if (ret != RET_OK) { + return; + } + return; +} + +void UpdateDragStyleFuzzTest(const uint8_t* data, size_t size) +{ + CALL_DEBUG_ENTER; + int32_t num = 0; + GetObject(data, size, num); + InteractionManager::GetInstance()->UpdateDragStyle(static_cast(num % DRAGCURSORSTYLE_MAX)); + return; +} +} // namespace DeviceStatus +} // namespace Msdp +} // namespace OHOS + +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + if (data == nullptr) { + return 0; + } + if (size < sizeof(int32_t)) { + return 0; + } + OHOS::Msdp::DeviceStatus::UpdateDragStyleFuzzTest(data, size); + return 0; +} + diff --git a/test/fuzztest/updatedragstyle_fuzzer/updatedragstyle_fuzzer.h b/test/fuzztest/updatedragstyle_fuzzer/updatedragstyle_fuzzer.h new file mode 100644 index 000000000..e1c4d85b5 --- /dev/null +++ b/test/fuzztest/updatedragstyle_fuzzer/updatedragstyle_fuzzer.h @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2023 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 UPDATEDRAGSTYLE_FUZZER_H +#define UPDATEDRAGSTYLE_FUZZER_H + +#define FUZZ_PROJECT_NAME "updatedragstyle_fuzzer" + +#endif // UPDATEDRAGSTYLE_FUZZER_H \ No newline at end of file -- Gitee