mirror of
https://gitee.com/openharmony/communication_dsoftbus
synced 2024-12-29 21:14:50 +00:00
commit
a17182d281
@ -155,6 +155,7 @@
|
||||
"//foundation/communication/dsoftbus/tests/sdk/transmission/fuzztest/sessionserviceimpl_fuzzer:fuzztest",
|
||||
"//foundation/communication/dsoftbus/tests/sdk/transmission/fuzztest/closesession_fuzzer:fuzztest",
|
||||
"//foundation/communication/dsoftbus/tests/sdk/transmission/fuzztest/clienttransstream_fuzzer:fuzztest",
|
||||
"//foundation/communication/dsoftbus/tests/sdk/transmission/fuzztest/clienttranssessionservice_fuzzer:fuzztest",
|
||||
"//foundation/communication/dsoftbus/tests/sdk/transmission/fuzztest/clienttransudpstreaminterface_fuzzer:fuzztest",
|
||||
"//foundation/communication/dsoftbus/tests/sdk/transmission/fuzztest/clientqosmanager_fuzzer:fuzztest",
|
||||
"//foundation/communication/dsoftbus/tests/sdk/transmission/fuzztest/clienttranspending_fuzzer:fuzztest",
|
||||
|
@ -22,6 +22,7 @@ group("fuzztest") {
|
||||
"clienttransproxyfilemanager_fuzzer:fuzztest",
|
||||
"clienttransproxymanager_fuzzer:fuzztest",
|
||||
"clienttranssessionmanager_fuzzer:fuzztest",
|
||||
"clienttranssessionservice_fuzzer:fuzztest",
|
||||
"clienttransstream_fuzzer:fuzztest",
|
||||
"clienttranstcpdirectlistener_fuzzer:fuzztest",
|
||||
"clienttransudpmanager_fuzzer:fuzztest",
|
||||
|
@ -1,4 +1,4 @@
|
||||
# Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
# Copyright (c) 2021-2022 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
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
* Copyright (c) 2021-2022 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
|
||||
@ -28,9 +28,9 @@ static int OnSessionOpened(int sessionId, int result)
|
||||
}
|
||||
static void OnSessionClosed(int sessionId) {}
|
||||
|
||||
static void OnBytesReceived(int sessionId, const void *data, unsigned int len) {}
|
||||
static void OnBytesReceived(int sessionId, const void* data, unsigned int len) {}
|
||||
|
||||
static void OnMessageReceived(int sessionId, const void *data, unsigned int len) {}
|
||||
static void OnMessageReceived(int sessionId, const void* data, unsigned int len) {}
|
||||
|
||||
static ISessionListener g_sessionlistener = {
|
||||
.OnSessionOpened = OnSessionOpened,
|
||||
@ -44,7 +44,7 @@ void ClientAddNewSessionTest(const uint8_t* data, size_t size)
|
||||
if ((data == nullptr) || (size == 0)) {
|
||||
return;
|
||||
}
|
||||
const char *testSessionName = "testsessionname";
|
||||
const char* testSessionName = "testsessionname";
|
||||
SessionInfo session;
|
||||
ClientAddNewSession(testSessionName, &session);
|
||||
}
|
||||
@ -54,7 +54,7 @@ void ClientAddAuthSessionTest(const uint8_t* data, size_t size)
|
||||
if ((data == nullptr) || (size == 0)) {
|
||||
return;
|
||||
}
|
||||
const char *testSessionName = "testsessionname";
|
||||
const char* testSessionName = "testsessionname";
|
||||
int32_t sessionId = *(reinterpret_cast<const int32_t*>(data));
|
||||
ClientAddAuthSession(testSessionName, &sessionId);
|
||||
}
|
||||
@ -99,11 +99,73 @@ void ClientGetSessionCallbackTest(const uint8_t* data, size_t size)
|
||||
return;
|
||||
}
|
||||
int32_t sessionId = *(reinterpret_cast<const int32_t*>(data));
|
||||
const char *testSessionName = "testsessionname";
|
||||
const char* testSessionName = "testsessionname";
|
||||
|
||||
ClientGetSessionCallbackById(sessionId, &g_sessionlistener);
|
||||
ClientGetSessionCallbackByName(testSessionName, &g_sessionlistener);
|
||||
}
|
||||
|
||||
void ClientTransOnLinkDownTest(const uint8_t* data, size_t size)
|
||||
{
|
||||
if ((data == nullptr) || (size == 0)) {
|
||||
return;
|
||||
}
|
||||
char* networkId = nullptr;
|
||||
int32_t routeType = *(reinterpret_cast<const int32_t*>(data));
|
||||
|
||||
ClientTransOnLinkDown(networkId, routeType);
|
||||
}
|
||||
|
||||
void ClientRemovePermissionTest(const uint8_t* data, size_t size)
|
||||
{
|
||||
if ((data == nullptr) || (size == 0)) {
|
||||
return;
|
||||
}
|
||||
char tmp = *(reinterpret_cast<const char*>(data));
|
||||
ClientRemovePermission(&tmp);
|
||||
}
|
||||
|
||||
void ClientGetFileConfigInfoByIdTest(const uint8_t* data, size_t size)
|
||||
{
|
||||
if ((data == nullptr) || (size == 0)) {
|
||||
return;
|
||||
}
|
||||
int32_t sessionId = *(reinterpret_cast<const int32_t*>(data));
|
||||
ClientGetFileConfigInfoById(sessionId, NULL, NULL, NULL);
|
||||
}
|
||||
|
||||
void GetEncryptByChannelIdTest(const uint8_t* data, size_t size)
|
||||
{
|
||||
if ((data == nullptr) || (size == 0)) {
|
||||
return;
|
||||
}
|
||||
int32_t channelId = *(reinterpret_cast<const int32_t*>(data));
|
||||
int32_t channelType = *(reinterpret_cast<const int32_t*>(data));
|
||||
int32_t encryp = 0;
|
||||
GetEncryptByChannelId(channelId, channelType, &encryp);
|
||||
}
|
||||
|
||||
void ClientGetSessionIdByChannelIdTest(const uint8_t* data, size_t size)
|
||||
{
|
||||
if ((data == nullptr) || (size == 0)) {
|
||||
return;
|
||||
}
|
||||
int32_t channelId = *(reinterpret_cast<const int32_t*>(data));
|
||||
int32_t channelType = *(reinterpret_cast<const int32_t*>(data));
|
||||
int32_t sessionId;
|
||||
ClientGetSessionIdByChannelId(channelId, channelType, &sessionId);
|
||||
}
|
||||
|
||||
void ClientEnableSessionByChannelIdTest(const uint8_t* data, size_t size)
|
||||
{
|
||||
if ((data == nullptr) || (size == 0)) {
|
||||
return;
|
||||
}
|
||||
ChannelInfo channel;
|
||||
int32_t sessionId;
|
||||
ClientEnableSessionByChannelId(&channel, &sessionId);
|
||||
}
|
||||
|
||||
} // namespace OHOS
|
||||
|
||||
/* Fuzzer entry point */
|
||||
@ -115,6 +177,12 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
|
||||
OHOS::ClientGetSessionDataTest(data, size);
|
||||
OHOS::ClientSetChannelBySessionIdTest(data, size);
|
||||
OHOS::ClientGetSessionCallbackTest(data, size);
|
||||
OHOS::ClientTransOnLinkDownTest(data, size);
|
||||
OHOS::ClientRemovePermissionTest(data, size);
|
||||
OHOS::ClientGetFileConfigInfoByIdTest(data, size);
|
||||
OHOS::GetEncryptByChannelIdTest(data, size);
|
||||
OHOS::ClientGetSessionIdByChannelIdTest(data, size);
|
||||
OHOS::ClientEnableSessionByChannelIdTest(data, size);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Copyright (c) 2021-2022 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
|
||||
@ -25,4 +25,4 @@
|
||||
|
||||
#define FUZZ_PROJECT_NAME "clienttranssessionmanager_fuzzer"
|
||||
|
||||
#endif
|
||||
#endif
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Copyright (c) 2021-2022 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
|
||||
|
@ -0,0 +1,61 @@
|
||||
# Copyright (c) 2021-2022 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/ohos.gni")
|
||||
import("//build/test.gni")
|
||||
import("//foundation/communication/dsoftbus/dsoftbus.gni")
|
||||
|
||||
##############################fuzztest##########################################
|
||||
ohos_fuzztest("ClientTransSessionServiceFuzzTest") {
|
||||
module_out_path = "dsoftbus/transmission"
|
||||
fuzz_config_file = "//foundation/communication/dsoftbus/tests/sdk/transmission/fuzztest/clienttranssessionservice_fuzzer"
|
||||
include_dirs = [
|
||||
"//foundation/communication/dsoftbus/core/common/inner_communication",
|
||||
"//foundation/communication/dsoftbus/core/common/inner_communication",
|
||||
"//foundation/communication/dsoftbus/adapter/common/include",
|
||||
"//foundation/communication/dsoftbus/core/common/include",
|
||||
"//foundation/communication/dsoftbus/interfaces/kits/common",
|
||||
"//foundation/communication/dsoftbus/interfaces/kits/transport",
|
||||
"//foundation/communication/dsoftbus/interfaces/inner_kits/transport",
|
||||
"//foundation/communication/dsoftbus/sdk/transmission/trans_channel/udp/file/include",
|
||||
"//foundation/communication/dsoftbus/sdk/transmission/trans_channel/udp/common/include",
|
||||
"//foundation/communication/dsoftbus/components/nstackx/nstackx_core/dfile/interface/",
|
||||
"//foundation/communication/dsoftbus/components/nstackx/nstackx_util/interface",
|
||||
"//foundation/communication/dsoftbus/sdk/transmission/session/include",
|
||||
"//commonlibrary/c_utils/base/include",
|
||||
"//third_party/bounds_checking_function/include",
|
||||
]
|
||||
cflags = [
|
||||
"-g",
|
||||
"-O0",
|
||||
"-Wno-unused-variable",
|
||||
"-fno-omit-frame-pointer",
|
||||
"-fstack-protector-strong",
|
||||
]
|
||||
sources = [ "clienttranssessionservice_fuzzer.cpp" ]
|
||||
deps = [ "//foundation/communication/dsoftbus/sdk:softbus_client" ]
|
||||
|
||||
external_deps = [ "c_utils:utils" ]
|
||||
}
|
||||
|
||||
###############################################################################
|
||||
group("fuzztest") {
|
||||
testonly = true
|
||||
deps = [
|
||||
# deps file
|
||||
":ClientTransSessionServiceFuzzTest",
|
||||
]
|
||||
}
|
||||
###############################################################################
|
@ -0,0 +1,84 @@
|
||||
/*
|
||||
* Copyright (c) 2021-2022 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 "clienttranssessionservice_fuzzer.h"
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include "dfs_session.h"
|
||||
#include "session.h"
|
||||
#include "client_trans_session_service.h"
|
||||
|
||||
namespace OHOS {
|
||||
void GetSessionKeyTest(const uint8_t* data, size_t size)
|
||||
{
|
||||
if ((data == nullptr) || (size == 0)) {
|
||||
return;
|
||||
}
|
||||
|
||||
unsigned int len = *(reinterpret_cast<const uint32_t*>(size));
|
||||
int32_t sessionId = *(reinterpret_cast<const int32_t*>(size));
|
||||
char tmp = *(reinterpret_cast<const char*>(data));
|
||||
GetSessionKey(sessionId, &tmp, len);
|
||||
}
|
||||
|
||||
void GetSessionHandleTest(const uint8_t* data, size_t size)
|
||||
{
|
||||
if ((data == nullptr) || (size == 0)) {
|
||||
return;
|
||||
}
|
||||
int handle = 1;
|
||||
int32_t sessionId = *(reinterpret_cast<const int32_t*>(data));
|
||||
GetSessionHandle(sessionId, &handle);
|
||||
}
|
||||
|
||||
void DisableSessionListenerTest(const uint8_t* data, size_t size)
|
||||
{
|
||||
if ((data == nullptr) || (size == 0)) {
|
||||
return;
|
||||
}
|
||||
int32_t sessionId = *(reinterpret_cast<const int32_t*>(data));
|
||||
DisableSessionListener(sessionId);
|
||||
}
|
||||
|
||||
void OpenSessionSyncTest(const uint8_t* data, size_t size)
|
||||
{
|
||||
if ((data == nullptr) || (size == 0)) {
|
||||
return;
|
||||
}
|
||||
#define SESSION_NAME_SIZE_MAX 256
|
||||
#define DEVICE_ID_SIZE_MAX 65
|
||||
#define GROUP_ID_SIZE_MAX 65
|
||||
char mySessionName[SESSION_NAME_SIZE_MAX] = "ohos.fuzz.dms.test";
|
||||
char peerSessionName[SESSION_NAME_SIZE_MAX] = "ohos.fuzz.dms.test";
|
||||
char peerNetworkId[DEVICE_ID_SIZE_MAX] = "ABCDEF00ABCDEF00ABCDEF00ABCDEF00ABCDEF00ABCDEF00ABCDEF00ABCDEF00";
|
||||
SessionAttribute attr = {
|
||||
.dataType = TYPE_BYTES,
|
||||
};
|
||||
char groupId[GROUP_ID_SIZE_MAX] = "TEST_GROUP_ID";
|
||||
OpenSessionSync(mySessionName, peerSessionName, peerNetworkId, groupId, &attr);
|
||||
}
|
||||
}
|
||||
|
||||
/* Fuzzer entry point */
|
||||
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
|
||||
{
|
||||
/* Run your code on data */
|
||||
OHOS::GetSessionKeyTest(data, size);
|
||||
OHOS::GetSessionHandleTest(data, size);
|
||||
OHOS::DisableSessionListenerTest(data, size);
|
||||
OHOS::OpenSessionSyncTest(data, size);
|
||||
return 0;
|
||||
}
|
||||
|
@ -0,0 +1,28 @@
|
||||
/*
|
||||
* Copyright (c) 2021-2022 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 <cstdint>
|
||||
#include <unistd.h>
|
||||
#include <climits>
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <fcntl.h>
|
||||
|
||||
#ifndef CLIENTTRANSSESSIONSERVICE_FUZZER_H
|
||||
#define CLIENTTRANSSESSIONSERVICE_FUZZER_H
|
||||
|
||||
#define FUZZ_PROJECT_NAME "clienttranssessionservice_fuzzer"
|
||||
|
||||
#endif
|
@ -0,0 +1,16 @@
|
||||
/*
|
||||
* Copyright (c) 2021-2022 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,25 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Copyright (c) 2021 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>
|
Loading…
Reference in New Issue
Block a user