diff --git a/bundle.json b/bundle.json index 48e3c94c28..a533cd7da8 100644 --- a/bundle.json +++ b/bundle.json @@ -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", diff --git a/tests/sdk/transmission/fuzztest/BUILD.gn b/tests/sdk/transmission/fuzztest/BUILD.gn index fbfea69ca5..4f851acda2 100644 --- a/tests/sdk/transmission/fuzztest/BUILD.gn +++ b/tests/sdk/transmission/fuzztest/BUILD.gn @@ -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", diff --git a/tests/sdk/transmission/fuzztest/clienttranssessionmanager_fuzzer/BUILD.gn b/tests/sdk/transmission/fuzztest/clienttranssessionmanager_fuzzer/BUILD.gn index 463eb451cd..14af151984 100644 --- a/tests/sdk/transmission/fuzztest/clienttranssessionmanager_fuzzer/BUILD.gn +++ b/tests/sdk/transmission/fuzztest/clienttranssessionmanager_fuzzer/BUILD.gn @@ -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 diff --git a/tests/sdk/transmission/fuzztest/clienttranssessionmanager_fuzzer/clienttranssessionmanager_fuzzer.cpp b/tests/sdk/transmission/fuzztest/clienttranssessionmanager_fuzzer/clienttranssessionmanager_fuzzer.cpp index 21cda0f3c4..3f935f6284 100644 --- a/tests/sdk/transmission/fuzztest/clienttranssessionmanager_fuzzer/clienttranssessionmanager_fuzzer.cpp +++ b/tests/sdk/transmission/fuzztest/clienttranssessionmanager_fuzzer/clienttranssessionmanager_fuzzer.cpp @@ -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(data)); ClientAddAuthSession(testSessionName, &sessionId); } @@ -99,11 +99,73 @@ void ClientGetSessionCallbackTest(const uint8_t* data, size_t size) return; } int32_t sessionId = *(reinterpret_cast(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(data)); + + ClientTransOnLinkDown(networkId, routeType); +} + +void ClientRemovePermissionTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size == 0)) { + return; + } + char tmp = *(reinterpret_cast(data)); + ClientRemovePermission(&tmp); +} + +void ClientGetFileConfigInfoByIdTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size == 0)) { + return; + } + int32_t sessionId = *(reinterpret_cast(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(data)); + int32_t channelType = *(reinterpret_cast(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(data)); + int32_t channelType = *(reinterpret_cast(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; } diff --git a/tests/sdk/transmission/fuzztest/clienttranssessionmanager_fuzzer/clienttranssessionmanager_fuzzer.h b/tests/sdk/transmission/fuzztest/clienttranssessionmanager_fuzzer/clienttranssessionmanager_fuzzer.h index 411ff0934c..2292e2d38e 100644 --- a/tests/sdk/transmission/fuzztest/clienttranssessionmanager_fuzzer/clienttranssessionmanager_fuzzer.h +++ b/tests/sdk/transmission/fuzztest/clienttranssessionmanager_fuzzer/clienttranssessionmanager_fuzzer.h @@ -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 \ No newline at end of file diff --git a/tests/sdk/transmission/fuzztest/clienttranssessionmanager_fuzzer/corpus/init b/tests/sdk/transmission/fuzztest/clienttranssessionmanager_fuzzer/corpus/init index 6d6bd4a361..b332f8b5fa 100644 --- a/tests/sdk/transmission/fuzztest/clienttranssessionmanager_fuzzer/corpus/init +++ b/tests/sdk/transmission/fuzztest/clienttranssessionmanager_fuzzer/corpus/init @@ -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 diff --git a/tests/sdk/transmission/fuzztest/clienttranssessionservice_fuzzer/BUILD.gn b/tests/sdk/transmission/fuzztest/clienttranssessionservice_fuzzer/BUILD.gn new file mode 100644 index 0000000000..d5e842c433 --- /dev/null +++ b/tests/sdk/transmission/fuzztest/clienttranssessionservice_fuzzer/BUILD.gn @@ -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", + ] +} +############################################################################### diff --git a/tests/sdk/transmission/fuzztest/clienttranssessionservice_fuzzer/clienttranssessionservice_fuzzer.cpp b/tests/sdk/transmission/fuzztest/clienttranssessionservice_fuzzer/clienttranssessionservice_fuzzer.cpp new file mode 100644 index 0000000000..3b85bbfdd4 --- /dev/null +++ b/tests/sdk/transmission/fuzztest/clienttranssessionservice_fuzzer/clienttranssessionservice_fuzzer.cpp @@ -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 +#include +#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(size)); + int32_t sessionId = *(reinterpret_cast(size)); + char tmp = *(reinterpret_cast(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(data)); + GetSessionHandle(sessionId, &handle); + } + + void DisableSessionListenerTest(const uint8_t* data, size_t size) + { + if ((data == nullptr) || (size == 0)) { + return; + } + int32_t sessionId = *(reinterpret_cast(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; +} + diff --git a/tests/sdk/transmission/fuzztest/clienttranssessionservice_fuzzer/clienttranssessionservice_fuzzer.h b/tests/sdk/transmission/fuzztest/clienttranssessionservice_fuzzer/clienttranssessionservice_fuzzer.h new file mode 100644 index 0000000000..472d08ffc0 --- /dev/null +++ b/tests/sdk/transmission/fuzztest/clienttranssessionservice_fuzzer/clienttranssessionservice_fuzzer.h @@ -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 +#include +#include +#include +#include +#include + +#ifndef CLIENTTRANSSESSIONSERVICE_FUZZER_H +#define CLIENTTRANSSESSIONSERVICE_FUZZER_H + +#define FUZZ_PROJECT_NAME "clienttranssessionservice_fuzzer" + +#endif \ No newline at end of file diff --git a/tests/sdk/transmission/fuzztest/clienttranssessionservice_fuzzer/corpus/init b/tests/sdk/transmission/fuzztest/clienttranssessionservice_fuzzer/corpus/init new file mode 100644 index 0000000000..b332f8b5fa --- /dev/null +++ b/tests/sdk/transmission/fuzztest/clienttranssessionservice_fuzzer/corpus/init @@ -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 \ No newline at end of file diff --git a/tests/sdk/transmission/fuzztest/clienttranssessionservice_fuzzer/project.xml b/tests/sdk/transmission/fuzztest/clienttranssessionservice_fuzzer/project.xml new file mode 100644 index 0000000000..85e7ef2c1c --- /dev/null +++ b/tests/sdk/transmission/fuzztest/clienttranssessionservice_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + +