mirror of
https://gitee.com/openharmony/msdp_device_status
synced 2025-03-01 12:05:55 +00:00
addFuzz
Signed-off-by: wuliangdong <wuliangdong1@huawei.com> Change-Id: I5479ca8a978fc10e9ca7629e5753dd35374d63aa
This commit is contained in:
parent
917a18caf1
commit
d9086e02bf
1
BUILD.gn
1
BUILD.gn
@ -19,5 +19,6 @@ group("device_status_tests") {
|
||||
deps = [
|
||||
"services/native/test:devicestatussrv_test",
|
||||
"test/fuzztest:device_status_fuzztest",
|
||||
"frameworks/native/interaction/test:interaction_manager_test"
|
||||
]
|
||||
}
|
||||
|
@ -20,6 +20,8 @@ group("device_status_fuzztest") {
|
||||
deps += [
|
||||
"devicestatusagent_fuzzer:fuzztest",
|
||||
"devicestatusclient_fuzzer:fuzztest",
|
||||
"startdrag_fuzzer:fuzztest",
|
||||
"stopdrag_fuzzer:fuzztest",
|
||||
]
|
||||
if (fusion_interaction_coordination) {
|
||||
deps += [
|
||||
|
54
test/fuzztest/startdrag_fuzzer/BUILD.gn
Normal file
54
test/fuzztest/startdrag_fuzzer/BUILD.gn
Normal file
@ -0,0 +1,54 @@
|
||||
# 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")
|
||||
|
||||
#####################hydra-fuzz###################
|
||||
import("//build/config/features.gni")
|
||||
import("//build/test.gni")
|
||||
module_output_path = "device_status/device_status_native"
|
||||
|
||||
##############################fuzztest##########################################
|
||||
ohos_fuzztest("StartDragFuzzTest") {
|
||||
module_out_path = module_output_path
|
||||
fuzz_config_file =
|
||||
"//base/msdp/device_status/test/fuzztest/startdrag_fuzzer"
|
||||
include_dirs = [
|
||||
"//base/msdp/device_status/interfaces/innerkits/interaction/include",
|
||||
"//base/msdp/device_status/utils/common/include",
|
||||
]
|
||||
cflags = [
|
||||
"-g",
|
||||
"-O0",
|
||||
"-Wno-unused-variable",
|
||||
"-fno-omit-frame-pointer",
|
||||
]
|
||||
sources = [ "start_drag_fuzzer.cpp" ]
|
||||
deps =
|
||||
[ "//base/msdp/device_status/interfaces/innerkits:devicestatus_client" ]
|
||||
external_deps = [
|
||||
"c_utils:utils",
|
||||
"hiviewdfx_hilog_native:libhilog",
|
||||
"multimedia_image_framework:image_native",
|
||||
]
|
||||
}
|
||||
|
||||
###############################################################################
|
||||
group("fuzztest") {
|
||||
testonly = true
|
||||
deps = []
|
||||
deps += [
|
||||
":StartDragFuzzTest",
|
||||
]
|
||||
}
|
||||
###############################################################################
|
14
test/fuzztest/startdrag_fuzzer/corpus/init
Normal file
14
test/fuzztest/startdrag_fuzzer/corpus/init
Normal file
@ -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
|
25
test/fuzztest/startdrag_fuzzer/project.xml
Normal file
25
test/fuzztest/startdrag_fuzzer/project.xml
Normal file
@ -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>
|
116
test/fuzztest/startdrag_fuzzer/start_drag_fuzzer.cpp
Normal file
116
test/fuzztest/startdrag_fuzzer/start_drag_fuzzer.cpp
Normal file
@ -0,0 +1,116 @@
|
||||
/*
|
||||
* 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 "start_drag_fuzzer.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "securec.h"
|
||||
|
||||
#include "devicestatus_define.h"
|
||||
#include "drag_data.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, "StartDragFuzzTest" };
|
||||
} // namespace
|
||||
|
||||
|
||||
size_t GetObject(const uint8_t *data, size_t size, T &object)
|
||||
{
|
||||
size_t objectSize = sizeof(object);
|
||||
if (objectSize > size) {
|
||||
return 0;
|
||||
}
|
||||
errno_t ret = memcpy_s(&object, objectSize, data, objectSize);
|
||||
if (ret != RET_OK) {
|
||||
return 0;
|
||||
}
|
||||
return objectSize;
|
||||
}
|
||||
|
||||
std::shared_ptr<Media::PixelMap> CreatePixelMap(int32_t width, int32_t height)
|
||||
{
|
||||
CALL_DEBUG_ENTER;
|
||||
if (width <= 0 || width > MAX_PIXEL_MAP_WIDTH ||
|
||||
height <= 0 || height > MAX_PIXEL_MAP_HEIGHT) {
|
||||
FI_HILOGE("Invalid size,width:%{public}d,height:%{public}d", width, height);
|
||||
return nullptr;
|
||||
}
|
||||
OHOS::Media::InitializationOptions opts;
|
||||
opts.size.width = width;
|
||||
opts.size.height = height;
|
||||
std::unique_ptr<Media::PixelMap> uniquePixelMap = Media::PixelMap::Create(opts);
|
||||
std::shared_ptr<Media::PixelMap> pixelMap = std::move(uniquePixelMap);
|
||||
return pixelMap;
|
||||
}
|
||||
|
||||
DragData CreateDragData(const uint8_t* data, size_t size)
|
||||
{
|
||||
size_t startPos = 0;
|
||||
PictureResourse pictureResourse;
|
||||
startPos += GetObject<int32_t>(data + startPos, size - startPos, pictureResourse.x);
|
||||
startPos += GetObject<int32_t>(data + startPos, size - startPos, pictureResourse.y);
|
||||
int32_t width = 0;
|
||||
int32_t height = 0;
|
||||
startPos += GetObject<int32_t>(data + startPos, size - startPos, width);
|
||||
startPos += GetObject<int32_t>(data + startPos, size - startPos, height);
|
||||
pictureResourse.pixelMap = CreatePixelMap(width, height);
|
||||
|
||||
DragData dragData;
|
||||
startPos += GetObject<int32_t>(data + startPos, size - startPos, dragData.sourceType);
|
||||
startPos += GetObject<int32_t>(data + startPos, size - startPos, dragData.dragNum);
|
||||
startPos += GetObject<int32_t>(data + startPos, size - startPos, dragData.pointerId);
|
||||
startPos += GetObject<int32_t>(data + startPos, size - startPos, dragData.displayX);
|
||||
startPos += GetObject<int32_t>(data + startPos, size - startPos, dragData.displayY);
|
||||
startPos += GetObject<int32_t>(data + startPos, size - startPos, dragData.displayId);
|
||||
dragData.pictureResourse = pictureResourse;
|
||||
return dragData;
|
||||
}
|
||||
|
||||
void StartDragFuzzTest(const uint8_t* data, size_t size)
|
||||
{
|
||||
if (data == nullptr) {
|
||||
return;
|
||||
}
|
||||
auto func = [](const DragNotifyMsg& notifyMessage) {
|
||||
FI_HILOGD("StartDragFuzzTest:displayX:%{public}d, displayY:%{public}d, result:%{public}d, target:%{public}d",
|
||||
notifyMessage.displayX, notifyMessage.displayY, notifyMessage.result, notifyMessage.targetPid);
|
||||
};
|
||||
DragData dragData = CreateDragData(data, size);
|
||||
InteractionManager::GetInstance()->StartDrag(dragData, func);
|
||||
InteractionManager::GetInstance()->StopDrag(0);
|
||||
}
|
||||
} // namespace DeviceStatus
|
||||
} // namespace Msdp
|
||||
} // namespace OHOS
|
||||
|
||||
/* Fuzzer entry point */
|
||||
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::StartDragFuzzTest(data, size);
|
||||
return 0;
|
||||
}
|
||||
|
21
test/fuzztest/startdrag_fuzzer/start_drag_fuzzer.h
Normal file
21
test/fuzztest/startdrag_fuzzer/start_drag_fuzzer.h
Normal file
@ -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 START_DRAG_FUZZER_H
|
||||
#define START_DRAG_FUZZER_H
|
||||
|
||||
#define FUZZ_PROJECT_NAME "startdrag_fuzzer"
|
||||
|
||||
#endif // START_DRAG_FUZZER_H
|
54
test/fuzztest/stopdrag_fuzzer/BUILD.gn
Normal file
54
test/fuzztest/stopdrag_fuzzer/BUILD.gn
Normal file
@ -0,0 +1,54 @@
|
||||
# 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")
|
||||
|
||||
#####################hydra-fuzz###################
|
||||
import("//build/config/features.gni")
|
||||
import("//build/test.gni")
|
||||
module_output_path = "device_status/device_status_native"
|
||||
|
||||
##############################fuzztest##########################################
|
||||
ohos_fuzztest("StopDragFuzzTest") {
|
||||
module_out_path = module_output_path
|
||||
fuzz_config_file =
|
||||
"//base/msdp/device_status/test/fuzztest/stopdrag_fuzzer"
|
||||
include_dirs = [
|
||||
"//base/msdp/device_status/interfaces/innerkits/interaction/include",
|
||||
"//base/msdp/device_status/utils/common/include",
|
||||
]
|
||||
cflags = [
|
||||
"-g",
|
||||
"-O0",
|
||||
"-Wno-unused-variable",
|
||||
"-fno-omit-frame-pointer",
|
||||
]
|
||||
sources = [ "stop_drag_fuzzer.cpp" ]
|
||||
deps =
|
||||
[ "//base/msdp/device_status/interfaces/innerkits:devicestatus_client" ]
|
||||
external_deps = [
|
||||
"c_utils:utils",
|
||||
"hiviewdfx_hilog_native:libhilog",
|
||||
]
|
||||
}
|
||||
|
||||
###############################################################################
|
||||
group("fuzztest") {
|
||||
testonly = true
|
||||
deps = []
|
||||
deps += [
|
||||
# deps file
|
||||
":StopDragFuzzTest",
|
||||
]
|
||||
}
|
||||
###############################################################################
|
14
test/fuzztest/stopdrag_fuzzer/corpus/init
Normal file
14
test/fuzztest/stopdrag_fuzzer/corpus/init
Normal file
@ -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
|
25
test/fuzztest/stopdrag_fuzzer/project.xml
Normal file
25
test/fuzztest/stopdrag_fuzzer/project.xml
Normal file
@ -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>
|
52
test/fuzztest/stopdrag_fuzzer/stop_drag_fuzzer.cpp
Normal file
52
test/fuzztest/stopdrag_fuzzer/stop_drag_fuzzer.cpp
Normal file
@ -0,0 +1,52 @@
|
||||
/*
|
||||
* 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 "stop_drag_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, "StopDragFuzzTest" };
|
||||
} // namespace
|
||||
|
||||
void StopDragFuzzTest(const uint8_t* data, size_t size)
|
||||
{
|
||||
if (data == nullptr) {
|
||||
return;
|
||||
}
|
||||
int32_t result = *(reinterpret_cast<const int32_t*>(data));
|
||||
InteractionManager::GetInstance()->StopDrag(result);
|
||||
}
|
||||
} // namespace DeviceStatus
|
||||
} // namespace Msdp
|
||||
} // namespace OHOS
|
||||
|
||||
/* Fuzzer entry point */
|
||||
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::StopDragFuzzTest(data, size);
|
||||
return 0;
|
||||
}
|
||||
|
21
test/fuzztest/stopdrag_fuzzer/stop_drag_fuzzer.h
Normal file
21
test/fuzztest/stopdrag_fuzzer/stop_drag_fuzzer.h
Normal file
@ -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 STOP_DRAG_FUZZER_H
|
||||
#define STOP_DRAG_FUZZER_H
|
||||
|
||||
#define FUZZ_PROJECT_NAME "stopdrag_fuzzer"
|
||||
|
||||
#endif // STOP_DRAG_FUZZER_H
|
Loading…
x
Reference in New Issue
Block a user