diff --git a/test/fuzztest/BUILD.gn b/test/fuzztest/BUILD.gn index 2d05fe7c556fb2f4ba7eec28620b1ee94daefc59..1d915c7fecbb563b2cbd1823eb121e679de40669 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 0000000000000000000000000000000000000000..9a112648335f4792342cfec1b1635d07ec0bc35f --- /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 0000000000000000000000000000000000000000..e4ceac1bcd4e3b3427eb63cea0c28304064333cc --- /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 0000000000000000000000000000000000000000..2cdb74640f90e893de488833eb3c11e36e06f1d3 --- /dev/null +++ b/test/fuzztest/getshadowoffset_fuzzer/getshadowoffset_fuzzer.cpp @@ -0,0 +1,47 @@ +/* + * 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); +} +} // namespace DeviceStatus +} // namespace Msdp +} // namespace OHOS + +extern "C" int32_t 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 0000000000000000000000000000000000000000..2253f49827377fdb890448fa5501039fc50b57e2 --- /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 0000000000000000000000000000000000000000..bac4974e9068af3c045fbb5c3a588aa79e47faaf --- /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 0000000000000000000000000000000000000000..eab528a56b5cd516e1d17965cf1575ca6e44a0ce --- /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 0000000000000000000000000000000000000000..e4ceac1bcd4e3b3427eb63cea0c28304064333cc --- /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 0000000000000000000000000000000000000000..bac4974e9068af3c045fbb5c3a588aa79e47faaf --- /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 0000000000000000000000000000000000000000..88721a2f1a72e4befc51cfbdced883b768e7cf91 --- /dev/null +++ b/test/fuzztest/setdragwindowvisible_fuzzer/setdragwindowvisible_fuzzer.cpp @@ -0,0 +1,71 @@ +/* + * 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 != EOK) { + 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); +} +} // namespace DeviceStatus +} // namespace Msdp +} // namespace OHOS + +extern "C" int32_t 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 0000000000000000000000000000000000000000..411f9ecfb3f3226c2a4f1d9925bb1f66874c0816 --- /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 0000000000000000000000000000000000000000..f8e0ee5ab8fcff87f29d87c1e51d18810dc88d13 --- /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 0000000000000000000000000000000000000000..e4ceac1bcd4e3b3427eb63cea0c28304064333cc --- /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 0000000000000000000000000000000000000000..4fdbc407f205680885fa42663163b5c987f123a6 --- /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 0000000000000000000000000000000000000000..898fa5560c869963fef57c7070e2c2d238ae4ee8 --- /dev/null +++ b/test/fuzztest/updatedragstyle_fuzzer/updatedragstyle_fuzzer.cpp @@ -0,0 +1,67 @@ +/* + * 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 != EOK) { + 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)); +} +} // namespace DeviceStatus +} // namespace Msdp +} // namespace OHOS + +extern "C" int32_t 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 0000000000000000000000000000000000000000..e1c4d85b5a37873c9de0dddfb6d3689842a8f606 --- /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