!28 修改fuzz

Merge pull request !28 from 李天刚/master
This commit is contained in:
openharmony_ci
2023-06-07 03:36:20 +00:00
committed by Gitee
31 changed files with 801 additions and 93 deletions
+6 -2
View File
@@ -15,8 +15,12 @@ group("fuzztest") {
testonly = true
deps = [
"dinputsinkhandler_fuzzer:fuzztest",
"dinputsourcehandler_fuzzer:fuzztest",
"dinputconfigdh_fuzzer:fuzztest",
"dinputinitsink_fuzzer:fuzztest",
"dinputinitsource_fuzzer:fuzztest",
"dinputreleasesink_fuzzer:fuzztest",
"dinputreleasesource_fuzzer:fuzztest",
"dinputsubscribelocaldh_fuzzer:fuzztest",
"distributedinputclient_fuzzer:fuzztest",
"distributedinputkit_fuzzer:fuzztest",
"distributedinputsinktransport_fuzzer:fuzztest",
@@ -17,11 +17,11 @@ import("//build/test.gni")
import("../../../distributedinput.gni")
##############################fuzztest##########################################
ohos_fuzztest("DinputSourceHandlerFuzzTest") {
ohos_fuzztest("DinputConfigDhFuzzTest") {
module_out_path = "distributed_input/system"
fuzz_config_file =
"${distributedinput_path}/test/fuzztest/dinputsourcehandler_fuzzer"
"${distributedinput_path}/test/fuzztest/dinputconfigdh_fuzzer"
include_dirs = [
"include",
@@ -31,7 +31,6 @@ ohos_fuzztest("DinputSourceHandlerFuzzTest") {
"${distributedinput_path}/services/sink/sinkmanager/include",
"${distributedinput_path}/frameworks/include",
"${distributedinput_path}/sourcehandler/include",
"${distributedinput_path}/sinkhandler/include",
"${distributedinput_path}/inputdevicehandler/include",
"${service_common}/include",
"${common_path}/include",
@@ -53,7 +52,7 @@ ohos_fuzztest("DinputSourceHandlerFuzzTest") {
"-fno-omit-frame-pointer",
]
sources = [ "dinput_source_handler_fuzzer.cpp" ]
sources = [ "dinputconfigdh_fuzzer.cpp" ]
deps = [
"${distributedinput_path}/sourcehandler:libdinput_source_handler",
@@ -70,7 +69,7 @@ ohos_fuzztest("DinputSourceHandlerFuzzTest") {
defines = [
"HI_LOG_ENABLE",
"DH_LOG_TAG=\"DinputSourceHandlerFuzzTest\"",
"DH_LOG_TAG=\"DinputConfigDhFuzzTest\"",
"LOG_DOMAIN=0xD004100",
]
}
@@ -79,6 +78,6 @@ ohos_fuzztest("DinputSourceHandlerFuzzTest") {
group("fuzztest") {
testonly = true
deps = [ ":DinputSourceHandlerFuzzTest" ]
deps = [ ":DinputConfigDhFuzzTest" ]
}
###############################################################################
@@ -13,7 +13,7 @@
* limitations under the License.
*/
#include "dinput_source_handler_fuzzer.h"
#include "dinputconfigdh_fuzzer.h"
#include <cstddef>
#include <cstdint>
@@ -26,51 +26,11 @@
#include "constants_dinput.h"
#include "distributed_input_handler.h"
#include "distributed_input_kit.h"
#include "distributed_input_sink_handler.h"
#include "distributed_input_source_handler.h"
#include "i_distributed_sink_input.h"
#include "i_distributed_source_input.h"
namespace OHOS {
namespace DistributedHardware {
class TestRegisterInputCallback : public OHOS::DistributedHardware::RegisterCallback {
public:
TestRegisterInputCallback() = default;
virtual ~TestRegisterInputCallback() = default;
int32_t OnRegisterResult(const std::string &devId, const std::string &dhId, int32_t status,
const std::string &data) override
{
return 0;
}
};
class TestUnregisterInputCallback : public OHOS::DistributedHardware::UnregisterCallback {
public:
TestUnregisterInputCallback() = default;
virtual ~TestUnregisterInputCallback() = default;
int32_t OnUnregisterResult(const std::string &devId, const std::string &dhId, int32_t status,
const std::string &data) override
{
return 0;
}
};
void InitSourceFuzzTest(const uint8_t* data, size_t size)
{
if ((data == nullptr) || (size == 0)) {
return;
}
std::string params(reinterpret_cast<const char*>(data), size);
DistributedInput::DistributedInputSourceHandler::GetInstance().InitSource(params);
}
void ReleaseSourceFuzzTest(const uint8_t* data, size_t size)
{
(void)data;
(void)size;
DistributedInput::DistributedInputSourceHandler::GetInstance().ReleaseSource();
}
void ConfigDistributedHardwareFuzzTest(const uint8_t* data, size_t size)
{
if ((data == nullptr) || (size == 0)) {
@@ -89,8 +49,6 @@ void ConfigDistributedHardwareFuzzTest(const uint8_t* data, size_t size)
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
{
/* Run your code on data */
OHOS::DistributedHardware::InitSourceFuzzTest(data, size);
OHOS::DistributedHardware::ReleaseSourceFuzzTest(data, size);
OHOS::DistributedHardware::ConfigDistributedHardwareFuzzTest(data, size);
return 0;
}
@@ -14,9 +14,9 @@
*/
#ifndef DINPUT_SOURCE_HANDLER_FUZZER_H
#define DINPUT_SOURCE_HANDLER_FUZZER_H
#ifndef DINPUT_CONFIG_DH_FUZZER_H
#define DINPUT_CONFIG_DH_FUZZER_H
#define FUZZ_PROJECT_NAME "dinputsourcehandler_fuzzer"
#define FUZZ_PROJECT_NAME "dinputconfigdh_fuzzer"
#endif // DINPUT_SOURCE_HANDLER_FUZZER_H
#endif // DINPUT_CONFIG_DH_FUZZER_H
@@ -0,0 +1,83 @@
# Copyright (c) 2021-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.
#####################hydra-fuzz###################
import("//build/config/features.gni")
import("//build/test.gni")
import("../../../distributedinput.gni")
##############################fuzztest##########################################
ohos_fuzztest("DinputInitSinkFuzzTest") {
module_out_path = "distributed_input/system"
fuzz_config_file =
"${distributedinput_path}/test/fuzztest/dinputinitsink_fuzzer"
include_dirs = [
"include",
"${distributedinput_path}/interfaces/inner_kits/include",
"${distributedinput_path}/interfaces/ipc/include",
"${distributedinput_path}/services/source/sourcemanager/include",
"${distributedinput_path}/services/sink/sinkmanager/include",
"${distributedinput_path}/frameworks/include",
"${distributedinput_path}/sinkhandler/include",
"${distributedinput_path}/inputdevicehandler/include",
"${service_common}/include",
"${common_path}/include",
"${fwk_common_path}/log/include",
"${fwk_common_path}/utils/include",
"${fwk_utils_path}/include/log",
"${fwk_utils_path}/include",
"//third_party/json/include",
"${fwk_interfaces_path}/include",
"${fwk_interfaces_path}/include/ipc",
"${services_source_path}/inputinject/include",
"${utils_path}/include",
]
cflags = [
"-g",
"-O0",
"-Wno-unused-variable",
"-fno-omit-frame-pointer",
]
sources = [ "dinputinitsink_fuzzer.cpp" ]
deps = [
"${distributedinput_path}/sinkhandler:libdinput_sink_handler",
"//third_party/libevdev:libevdev",
]
external_deps = [
"c_utils:utils",
"dsoftbus:softbus_client",
"eventhandler:libeventhandler",
"ipc:ipc_core",
"safwk:system_ability_fwk",
]
defines = [
"HI_LOG_ENABLE",
"DH_LOG_TAG=\"DinputInitSinkFuzzTest\"",
"LOG_DOMAIN=0xD004100",
]
}
###############################################################################
group("fuzztest") {
testonly = true
deps = [ ":DinputInitSinkFuzzTest" ]
}
###############################################################################
@@ -0,0 +1,51 @@
/*
* 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 "dinputinitsink_fuzzer.h"
#include <cstddef>
#include <cstdint>
#include <functional>
#include <iostream>
#include <thread>
#include <refbase.h>
#include "constants_dinput.h"
#include "distributed_input_handler.h"
#include "distributed_input_kit.h"
#include "distributed_input_sink_handler.h"
#include "i_distributed_sink_input.h"
namespace OHOS {
namespace DistributedHardware {
void InitSinkFuzzTest(const uint8_t* data, size_t size)
{
if ((data == nullptr) || (size == 0)) {
return;
}
std::string params(reinterpret_cast<const char*>(data), size);
DistributedInput::DistributedInputSinkHandler::GetInstance().InitSink(params);
}
} // namespace DistributedHardware
} // namespace OHOS
/* Fuzzer entry point */
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
{
/* Run your code on data */
OHOS::DistributedHardware::InitSinkFuzzTest(data, size);
return 0;
}
@@ -0,0 +1,22 @@
/*
* 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 DINPUT_INIT_SINK_FUZZER_H
#define DINPUT_INIT_SINK_FUZZER_H
#define FUZZ_PROJECT_NAME "dinputreleasesink_fuzzer"
#endif // DINPUT_INIT_SINK_FUZZER_H
@@ -0,0 +1,83 @@
# 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.
#####################hydra-fuzz###################
import("//build/config/features.gni")
import("//build/test.gni")
import("../../../distributedinput.gni")
##############################fuzztest##########################################
ohos_fuzztest("DinputInitSourceFuzzTest") {
module_out_path = "distributed_input/system"
fuzz_config_file =
"${distributedinput_path}/test/fuzztest/dinputinitsource_fuzzer"
include_dirs = [
"include",
"${distributedinput_path}/interfaces/inner_kits/include",
"${distributedinput_path}/interfaces/ipc/include",
"${distributedinput_path}/services/source/sourcemanager/include",
"${distributedinput_path}/services/sink/sinkmanager/include",
"${distributedinput_path}/frameworks/include",
"${distributedinput_path}/sourcehandler/include",
"${distributedinput_path}/inputdevicehandler/include",
"${service_common}/include",
"${common_path}/include",
"${fwk_common_path}/log/include",
"${fwk_common_path}/utils/include",
"${fwk_utils_path}/include/log",
"${fwk_utils_path}/include",
"//third_party/json/include",
"${fwk_interfaces_path}/include",
"${fwk_interfaces_path}/include/ipc",
"${services_source_path}/inputinject/include",
"${utils_path}/include",
]
cflags = [
"-g",
"-O0",
"-Wno-unused-variable",
"-fno-omit-frame-pointer",
]
sources = [ "dinputinitsource_fuzzer.cpp" ]
deps = [
"${distributedinput_path}/sourcehandler:libdinput_source_handler",
"//third_party/libevdev:libevdev",
]
external_deps = [
"c_utils:utils",
"dsoftbus:softbus_client",
"eventhandler:libeventhandler",
"ipc:ipc_core",
"safwk:system_ability_fwk",
]
defines = [
"HI_LOG_ENABLE",
"DH_LOG_TAG=\"DinputInitSourceFuzzTest\"",
"LOG_DOMAIN=0xD004100",
]
}
###############################################################################
group("fuzztest") {
testonly = true
deps = [ ":DinputInitSourceFuzzTest" ]
}
###############################################################################
@@ -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
@@ -0,0 +1,51 @@
/*
* 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 "dinputinitsource_fuzzer.h"
#include <cstddef>
#include <cstdint>
#include <functional>
#include <iostream>
#include <thread>
#include <refbase.h>
#include "constants_dinput.h"
#include "distributed_input_handler.h"
#include "distributed_input_kit.h"
#include "distributed_input_source_handler.h"
#include "i_distributed_source_input.h"
namespace OHOS {
namespace DistributedHardware {
void InitSourceFuzzTest(const uint8_t* data, size_t size)
{
if ((data == nullptr) || (size == 0)) {
return;
}
std::string params(reinterpret_cast<const char*>(data), size);
DistributedInput::DistributedInputSourceHandler::GetInstance().InitSource(params);
}
} // namespace DistributedHardware
} // namespace OHOS
/* Fuzzer entry point */
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
{
/* Run your code on data */
OHOS::DistributedHardware::InitSourceFuzzTest(data, size);
return 0;
}
@@ -0,0 +1,22 @@
/*
* 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 DINPUT_INIT_SOURCE_FUZZER_H
#define DINPUT_INIT_SOURCE_FUZZER_H
#define FUZZ_PROJECT_NAME "dinputinitsource_fuzzer"
#endif // DINPUT_INIT_SOURCE_FUZZER_H
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- 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_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>
@@ -17,11 +17,11 @@ import("//build/test.gni")
import("../../../distributedinput.gni")
##############################fuzztest##########################################
ohos_fuzztest("DinputSinkHandlerFuzzTest") {
ohos_fuzztest("DinputReleaseSinkFuzzTest") {
module_out_path = "distributed_input/system"
fuzz_config_file =
"${distributedinput_path}/test/fuzztest/dinputsinkhandler_fuzzer"
"${distributedinput_path}/test/fuzztest/dinputreleasesink_fuzzer"
include_dirs = [
"include",
@@ -30,7 +30,6 @@ ohos_fuzztest("DinputSinkHandlerFuzzTest") {
"${distributedinput_path}/services/source/sourcemanager/include",
"${distributedinput_path}/services/sink/sinkmanager/include",
"${distributedinput_path}/frameworks/include",
"${distributedinput_path}/sourcehandler/include",
"${distributedinput_path}/sinkhandler/include",
"${distributedinput_path}/inputdevicehandler/include",
"${service_common}/include",
@@ -53,7 +52,7 @@ ohos_fuzztest("DinputSinkHandlerFuzzTest") {
"-fno-omit-frame-pointer",
]
sources = [ "dinput_sink_handler_fuzzer.cpp" ]
sources = [ "dinputreleasesink_fuzzer.cpp" ]
deps = [
"${distributedinput_path}/sinkhandler:libdinput_sink_handler",
@@ -70,7 +69,7 @@ ohos_fuzztest("DinputSinkHandlerFuzzTest") {
defines = [
"HI_LOG_ENABLE",
"DH_LOG_TAG=\"DinputSinkHandlerFuzzTest\"",
"DH_LOG_TAG=\"DinputReleaseSinkFuzzTest\"",
"LOG_DOMAIN=0xD004100",
]
}
@@ -79,6 +78,6 @@ ohos_fuzztest("DinputSinkHandlerFuzzTest") {
group("fuzztest") {
testonly = true
deps = [ ":DinputSinkHandlerFuzzTest" ]
deps = [ ":DinputReleaseSinkFuzzTest" ]
}
###############################################################################
@@ -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
@@ -0,0 +1,49 @@
/*
* 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 "dinputreleasesink_fuzzer.h"
#include <cstddef>
#include <cstdint>
#include <functional>
#include <iostream>
#include <thread>
#include <refbase.h>
#include "constants_dinput.h"
#include "distributed_input_handler.h"
#include "distributed_input_kit.h"
#include "distributed_input_sink_handler.h"
#include "i_distributed_sink_input.h"
namespace OHOS {
namespace DistributedHardware {
void ReleaseSinkFuzzTest(const uint8_t* data, size_t size)
{
(void)data;
(void)size;
DistributedInput::DistributedInputSinkHandler::GetInstance().ReleaseSink();
}
} // namespace DistributedHardware
} // namespace OHOS
/* Fuzzer entry point */
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
{
/* Run your code on data */
OHOS::DistributedHardware::ReleaseSinkFuzzTest(data, size);
return 0;
}
@@ -14,9 +14,9 @@
*/
#ifndef DINPUT_SINK_HANDLER_FUZZER_H
#define DINPUT_SINK_HANDLER_FUZZER_H
#ifndef DINPUT_RELEASE_SINK_FUZZER_H
#define DINPUT_RELEASE_SINK_FUZZER_H
#define FUZZ_PROJECT_NAME "dinputsinkhandler_fuzzer"
#endif // DINPUT_SINK_HANDLER_FUZZER_H
#endif // DINPUT_RELEASE_SINK_FUZZER_H
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- 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_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>
@@ -0,0 +1,83 @@
# 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.
#####################hydra-fuzz###################
import("//build/config/features.gni")
import("//build/test.gni")
import("../../../distributedinput.gni")
##############################fuzztest##########################################
ohos_fuzztest("DinputReleaseSourceFuzzTest") {
module_out_path = "distributed_input/system"
fuzz_config_file =
"${distributedinput_path}/test/fuzztest/dinputreleasesource_fuzzer"
include_dirs = [
"include",
"${distributedinput_path}/interfaces/inner_kits/include",
"${distributedinput_path}/interfaces/ipc/include",
"${distributedinput_path}/services/source/sourcemanager/include",
"${distributedinput_path}/services/sink/sinkmanager/include",
"${distributedinput_path}/frameworks/include",
"${distributedinput_path}/sourcehandler/include",
"${distributedinput_path}/inputdevicehandler/include",
"${service_common}/include",
"${common_path}/include",
"${fwk_common_path}/log/include",
"${fwk_common_path}/utils/include",
"${fwk_utils_path}/include/log",
"${fwk_utils_path}/include",
"//third_party/json/include",
"${fwk_interfaces_path}/include",
"${fwk_interfaces_path}/include/ipc",
"${services_source_path}/inputinject/include",
"${utils_path}/include",
]
cflags = [
"-g",
"-O0",
"-Wno-unused-variable",
"-fno-omit-frame-pointer",
]
sources = [ "dinputreleasesource_fuzzer.cpp" ]
deps = [
"${distributedinput_path}/sourcehandler:libdinput_source_handler",
"//third_party/libevdev:libevdev",
]
external_deps = [
"c_utils:utils",
"dsoftbus:softbus_client",
"eventhandler:libeventhandler",
"ipc:ipc_core",
"safwk:system_ability_fwk",
]
defines = [
"HI_LOG_ENABLE",
"DH_LOG_TAG=\"DinputReleaseSourceFuzzTest\"",
"LOG_DOMAIN=0xD004100",
]
}
###############################################################################
group("fuzztest") {
testonly = true
deps = [ ":DinputReleaseSourceFuzzTest" ]
}
###############################################################################
@@ -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
@@ -0,0 +1,49 @@
/*
* 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 "dinputreleasesource_fuzzer.h"
#include <cstddef>
#include <cstdint>
#include <functional>
#include <iostream>
#include <thread>
#include <refbase.h>
#include "constants_dinput.h"
#include "distributed_input_handler.h"
#include "distributed_input_kit.h"
#include "distributed_input_source_handler.h"
#include "i_distributed_source_input.h"
namespace OHOS {
namespace DistributedHardware {
void ReleaseSourceFuzzTest(const uint8_t* data, size_t size)
{
(void)data;
(void)size;
DistributedInput::DistributedInputSourceHandler::GetInstance().ReleaseSource();
}
} // namespace DistributedHardware
} // namespace OHOS
/* Fuzzer entry point */
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
{
/* Run your code on data */
OHOS::DistributedHardware::ReleaseSourceFuzzTest(data, size);
return 0;
}
@@ -0,0 +1,22 @@
/*
* 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 DINPUT_RELEASE_SOURCE_FUZZER_H
#define DINPUT_RELEASE_SOURCE_FUZZER_H
#define FUZZ_PROJECT_NAME "dinputreleasesource_fuzzer"
#endif // DINPUT_RELEASE_SOURCE_FUZZER_H
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- 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_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>
@@ -0,0 +1,83 @@
# Copyright (c) 2021-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.
#####################hydra-fuzz###################
import("//build/config/features.gni")
import("//build/test.gni")
import("../../../distributedinput.gni")
##############################fuzztest##########################################
ohos_fuzztest("DinputSubscribeLocalDhFuzzTest") {
module_out_path = "distributed_input/system"
fuzz_config_file =
"${distributedinput_path}/test/fuzztest/dinputsubscribelocaldh_fuzzer"
include_dirs = [
"include",
"${distributedinput_path}/interfaces/inner_kits/include",
"${distributedinput_path}/interfaces/ipc/include",
"${distributedinput_path}/services/source/sourcemanager/include",
"${distributedinput_path}/services/sink/sinkmanager/include",
"${distributedinput_path}/frameworks/include",
"${distributedinput_path}/sinkhandler/include",
"${distributedinput_path}/inputdevicehandler/include",
"${service_common}/include",
"${common_path}/include",
"${fwk_common_path}/log/include",
"${fwk_common_path}/utils/include",
"${fwk_utils_path}/include/log",
"${fwk_utils_path}/include",
"//third_party/json/include",
"${fwk_interfaces_path}/include",
"${fwk_interfaces_path}/include/ipc",
"${services_source_path}/inputinject/include",
"${utils_path}/include",
]
cflags = [
"-g",
"-O0",
"-Wno-unused-variable",
"-fno-omit-frame-pointer",
]
sources = [ "dinputsubscribelocaldh_fuzzer.cpp" ]
deps = [
"${distributedinput_path}/sinkhandler:libdinput_sink_handler",
"//third_party/libevdev:libevdev",
]
external_deps = [
"c_utils:utils",
"dsoftbus:softbus_client",
"eventhandler:libeventhandler",
"ipc:ipc_core",
"safwk:system_ability_fwk",
]
defines = [
"HI_LOG_ENABLE",
"DH_LOG_TAG=\"DinputSubscribeLocalDhFuzzTest\"",
"LOG_DOMAIN=0xD004100",
]
}
###############################################################################
group("fuzztest") {
testonly = true
deps = [ ":DinputSubscribeLocalDhFuzzTest" ]
}
###############################################################################
@@ -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
@@ -13,7 +13,7 @@
* limitations under the License.
*/
#include "dinput_sink_handler_fuzzer.h"
#include "dinputsubscribelocaldh_fuzzer.h"
#include <cstddef>
#include <cstdint>
@@ -27,28 +27,10 @@
#include "distributed_input_handler.h"
#include "distributed_input_kit.h"
#include "distributed_input_sink_handler.h"
#include "distributed_input_source_handler.h"
#include "i_distributed_sink_input.h"
#include "i_distributed_source_input.h"
namespace OHOS {
namespace DistributedHardware {
void InitSinkFuzzTest(const uint8_t* data, size_t size)
{
if ((data == nullptr) || (size == 0)) {
return;
}
std::string params(reinterpret_cast<const char*>(data), size);
DistributedInput::DistributedInputSinkHandler::GetInstance().InitSink(params);
}
void ReleaseSinkFuzzTest(const uint8_t* data, size_t size)
{
(void)data;
(void)size;
DistributedInput::DistributedInputSinkHandler::GetInstance().ReleaseSink();
}
void SubscribeLocalHardwareFuzzTest(const uint8_t* data, size_t size)
{
if ((data == nullptr) || (size == 0)) {
@@ -57,14 +39,7 @@ void SubscribeLocalHardwareFuzzTest(const uint8_t* data, size_t size)
std::string dhId(reinterpret_cast<const char*>(data), size);
std::string params(reinterpret_cast<const char*>(data), size);
DistributedInput::DistributedInputSinkHandler::GetInstance().SubscribeLocalHardware(dhId, params);
}
void UnsubscribeLocalHardwareFuzzTest(const uint8_t* data, size_t size)
{
if ((data == nullptr) || (size == 0)) {
return;
}
std::string dhId(reinterpret_cast<const char*>(data), size);
DistributedInput::DistributedInputSinkHandler::GetInstance().UnsubscribeLocalHardware(dhId);
}
} // namespace DistributedHardware
@@ -74,9 +49,6 @@ void UnsubscribeLocalHardwareFuzzTest(const uint8_t* data, size_t size)
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
{
/* Run your code on data */
OHOS::DistributedHardware::InitSinkFuzzTest(data, size);
OHOS::DistributedHardware::ReleaseSinkFuzzTest(data, size);
OHOS::DistributedHardware::SubscribeLocalHardwareFuzzTest(data, size);
OHOS::DistributedHardware::UnsubscribeLocalHardwareFuzzTest(data, size);
return 0;
}
@@ -0,0 +1,22 @@
/*
* 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 DINPUT_SUBSCRIBE_LOCAL_DH_FUZZER_H
#define DINPUT_SUBSCRIBE_LOCAL_DH_FUZZER_H
#define FUZZ_PROJECT_NAME "dinputsubscribelocaldh_fuzzer"
#endif // DINPUT_SUBSCRIBE_LOCAL_DH_FUZZER_H
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- 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_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>