diff --git a/test/fuzztest/BUILD.gn b/test/fuzztest/BUILD.gn index 6ed190c71f3c8a6707bb72392239b01cc5bc54d4..3fcd403c71bccf3f9704e4cd861a1f0218b9f544 100644 --- a/test/fuzztest/BUILD.gn +++ b/test/fuzztest/BUILD.gn @@ -36,9 +36,7 @@ group("fuzztest") { "player_fuzztest/playermp4_fuzzer:PlayerMp4FuzzTest", "player_fuzztest/playerseek_fuzzer:PlayerSeekFuzzTest", "player_fuzztest/playersei_fuzzer:PlayerSeiFuzzTest", - "player_fuzztest/playerservicestub_fuzzer:PlayerServiceStubFuzzTest", "player_fuzztest/playersetvolume_fuzzer:PlayerSetVolumeFuzzTest", - "player_fuzztest/playerstub_fuzzer:PlayerStubFuzzTest", "recorder_fuzztest/recorderservicestub_fuzzer:RecorderServiceStubFuzzTest", "recorder_fuzztest/recordersetaudiochannels_fuzzer:RecorderSetAudioChannelsFuzzTest", "recorder_fuzztest/recordersetaudiochannelsnum_fuzzer:RecorderSetAudioChannelsNumFuzzTest", diff --git a/test/fuzztest/monitor_fuzztest/monitorservicestub_fuzzer/BUILD.gn b/test/fuzztest/monitor_fuzztest/monitorservicestub1_fuzzer/BUILD.gn similarity index 96% rename from test/fuzztest/monitor_fuzztest/monitorservicestub_fuzzer/BUILD.gn rename to test/fuzztest/monitor_fuzztest/monitorservicestub1_fuzzer/BUILD.gn index 7e6e9d48e3cc0787ed7630937347413157bdbc71..45bc97e3ed7dc9d32d165abc9c14907233749716 100644 --- a/test/fuzztest/monitor_fuzztest/monitorservicestub_fuzzer/BUILD.gn +++ b/test/fuzztest/monitor_fuzztest/monitorservicestub1_fuzzer/BUILD.gn @@ -18,10 +18,10 @@ import("//foundation/multimedia/player_framework/config.gni") MEDIA_ROOT_DIR = "//foundation/multimedia/player_framework/" ##############################fuzztest########################################## -ohos_fuzztest("MonitorServiceStubFuzzTest") { +ohos_fuzztest("MonitorServiceStub1FuzzTest") { module_out_path = "$MODULE_OUTPUT_PATH/monitor" fuzz_config_file = - "$MEDIA_ROOT_DIR/test/fuzztest/monitor_fuzztest/monitorservicestub_fuzzer" + "$MEDIA_ROOT_DIR/test/fuzztest/monitor_fuzztest/monitorservicestub1_fuzzer" resource_config_file = "$MEDIA_ROOT_DIR/test/fuzztest/resource/ohos_test.xml" include_dirs = [ @@ -61,7 +61,7 @@ ohos_fuzztest("MonitorServiceStubFuzzTest") { if (player_framework_support_monitor) { sources = [ "../../../../test/fuzztest/common/stub_common.cpp", - "monitorservicestub_fuzzer.cpp", + "monitorservicestub1_fuzzer.cpp", ] } deps = [ diff --git a/test/fuzztest/monitor_fuzztest/monitorservicestub_fuzzer/corpus/init b/test/fuzztest/monitor_fuzztest/monitorservicestub1_fuzzer/corpus/init similarity index 97% rename from test/fuzztest/monitor_fuzztest/monitorservicestub_fuzzer/corpus/init rename to test/fuzztest/monitor_fuzztest/monitorservicestub1_fuzzer/corpus/init index d27c29f2d9d44dbc2999359e54b643d02932fd86..6198079a28e860189d4294f6598f8ac6804c0dff 100644 --- a/test/fuzztest/monitor_fuzztest/monitorservicestub_fuzzer/corpus/init +++ b/test/fuzztest/monitor_fuzztest/monitorservicestub1_fuzzer/corpus/init @@ -1,16 +1,16 @@ -/* - * Copyright (c) 2024 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. - */ - +/* + * Copyright (c) 2024 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/monitor_fuzztest/monitorservicestub_fuzzer/monitorservicestub_fuzzer.cpp b/test/fuzztest/monitor_fuzztest/monitorservicestub1_fuzzer/monitorservicestub1_fuzzer.cpp similarity index 83% rename from test/fuzztest/monitor_fuzztest/monitorservicestub_fuzzer/monitorservicestub_fuzzer.cpp rename to test/fuzztest/monitor_fuzztest/monitorservicestub1_fuzzer/monitorservicestub1_fuzzer.cpp index 9e29a54fac23ab0f9471f07a020af46cc4f20147..fe63c19cc3d6b673fa548b4dd5cc28fb9129a07f 100644 --- a/test/fuzztest/monitor_fuzztest/monitorservicestub_fuzzer/monitorservicestub_fuzzer.cpp +++ b/test/fuzztest/monitor_fuzztest/monitorservicestub1_fuzzer/monitorservicestub1_fuzzer.cpp @@ -1,98 +1,95 @@ -/* - * Copyright (c) 2024 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 "monitorservicestub_fuzzer.h" -#include -#include -#include "string_ex.h" -#include "directory_ex.h" -#include -#include "media_server.h" -#include "media_parcel.h" -#include "i_standard_monitor_service.h" -#include "stub_common.h" - -using namespace std; -using namespace OHOS; -using namespace Media; - -namespace OHOS { -namespace Media { -MonitorServiceStubFuzzer::MonitorServiceStubFuzzer() -{ -} - -MonitorServiceStubFuzzer::~MonitorServiceStubFuzzer() -{ -} - -const int32_t SYSTEM_ABILITY_ID = 3002; -const bool RUN_ON_CREATE = false; -bool MonitorServiceStubFuzzer::FuzzMonitorOnRemoteRequest(uint8_t *data, size_t size) -{ - if (data == nullptr || size < sizeof(int64_t)) { - return true; - } - std::shared_ptr mediaServer = - std::make_shared(SYSTEM_ABILITY_ID, RUN_ON_CREATE); - sptr listener = new(std::nothrow) MediaListenerStubFuzzer(); - sptr monitor = mediaServer->GetSubSystemAbility( - IStandardMediaService::MediaSystemAbility::MEDIA_MONITOR, listener); - if (monitor == nullptr) { - return false; - } - - sptr> monitorStub = - iface_cast>(monitor); - if (monitorStub == nullptr) { - return false; - } - - const int maxIpcNum = 10; - for (uint32_t code = 0; code <= maxIpcNum; code++) { - MessageParcel msg; - msg.WriteInterfaceToken(monitorStub->GetDescriptor()); - msg.WriteBuffer(data, size); - msg.RewindRead(0); - MessageParcel reply; - MessageOption option; - monitorStub->OnRemoteRequest(code, msg, reply, option); - } - - return true; -} -} - -bool FuzzTestMonitorOnRemoteRequest(uint8_t *data, size_t size) -{ - if (data == nullptr) { - return true; - } - - if (size < sizeof(int32_t)) { - return true; - } - MonitorServiceStubFuzzer testMonitor; - return testMonitor.FuzzMonitorOnRemoteRequest(data, size); -} -} - -/* Fuzzer entry point */ -extern "C" int LLVMFuzzerTestOneInput(uint8_t *data, size_t size) -{ - /* Run your code on data */ - OHOS::FuzzTestMonitorOnRemoteRequest(data, size); - return 0; +/* + * Copyright (c) 2024 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 "monitorservicestub_fuzzer.h" +#include +#include +#include "string_ex.h" +#include "directory_ex.h" +#include +#include "media_server.h" +#include "media_parcel.h" +#include "i_standard_monitor_service.h" +#include "stub_common.h" + +using namespace std; +using namespace OHOS; +using namespace Media; + +namespace OHOS { +namespace Media { +MonitorServiceStubFuzzer::MonitorServiceStubFuzzer() +{ +} + +MonitorServiceStubFuzzer::~MonitorServiceStubFuzzer() +{ +} + +const int32_t SYSTEM_ABILITY_ID = 3002; +const bool RUN_ON_CREATE = false; +bool MonitorServiceStubFuzzer::FuzzMonitorOnRemoteRequest(uint8_t *data, size_t size) +{ + if (data == nullptr || size < sizeof(int64_t)) { + return true; + } + std::shared_ptr mediaServer = + std::make_shared(SYSTEM_ABILITY_ID, RUN_ON_CREATE); + sptr listener = new(std::nothrow) MediaListenerStubFuzzer(); + sptr monitor = mediaServer->GetSubSystemAbility( + IStandardMediaService::MediaSystemAbility::MEDIA_MONITOR, listener); + if (monitor == nullptr) { + return false; + } + + sptr> monitorStub = + iface_cast>(monitor); + if (monitorStub == nullptr) { + return false; + } + + uint32_t code = 0; + MessageParcel msg; + msg.WriteInterfaceToken(monitorStub->GetDescriptor()); + msg.WriteBuffer(data, size); + msg.RewindRead(0); + MessageParcel reply; + MessageOption option; + monitorStub->OnRemoteRequest(code, msg, reply, option); + return true; +} +} + +bool FuzzTestMonitorOnRemoteRequest(uint8_t *data, size_t size) +{ + if (data == nullptr) { + return true; + } + + if (size < sizeof(int32_t)) { + return true; + } + MonitorServiceStubFuzzer testMonitor; + return testMonitor.FuzzMonitorOnRemoteRequest(data, size); +} +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(uint8_t *data, size_t size) +{ + /* Run your code on data */ + OHOS::FuzzTestMonitorOnRemoteRequest(data, size); + return 0; } \ No newline at end of file diff --git a/test/fuzztest/monitor_fuzztest/monitorservicestub_fuzzer/monitorservicestub_fuzzer.h b/test/fuzztest/monitor_fuzztest/monitorservicestub1_fuzzer/monitorservicestub_fuzzer.h similarity index 96% rename from test/fuzztest/monitor_fuzztest/monitorservicestub_fuzzer/monitorservicestub_fuzzer.h rename to test/fuzztest/monitor_fuzztest/monitorservicestub1_fuzzer/monitorservicestub_fuzzer.h index e43476c5b3709244b650b61283307f5126e6b0df..41dc6a3991889160d83bdf74910229bc05e52cc1 100644 --- a/test/fuzztest/monitor_fuzztest/monitorservicestub_fuzzer/monitorservicestub_fuzzer.h +++ b/test/fuzztest/monitor_fuzztest/monitorservicestub1_fuzzer/monitorservicestub_fuzzer.h @@ -1,39 +1,39 @@ -/* - * Copyright (c) 2024 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 MONITORSERVICESTUB_FUZZER -#define MONITORSERVICESTUB_FUZZER - -#include -#include -#include -#include -#include -#include - -#define FUZZ_PROJECT_NAME "monitorservicestub_fuzzer" - -namespace OHOS { -namespace Media { -class MonitorServiceStubFuzzer { -public: - MonitorServiceStubFuzzer(); - ~MonitorServiceStubFuzzer(); - bool FuzzMonitorOnRemoteRequest(uint8_t *data, size_t size); -}; -} -bool FuzzTestMonitorOnRemoteRequest(uint8_t *data, size_t size); -} +/* + * Copyright (c) 2024 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 MONITORSERVICESTUB_FUZZER +#define MONITORSERVICESTUB_FUZZER + +#include +#include +#include +#include +#include +#include + +#define FUZZ_PROJECT_NAME "monitorservicestub_fuzzer" + +namespace OHOS { +namespace Media { +class MonitorServiceStubFuzzer { +public: + MonitorServiceStubFuzzer(); + ~MonitorServiceStubFuzzer(); + bool FuzzMonitorOnRemoteRequest(uint8_t *data, size_t size); +}; +} +bool FuzzTestMonitorOnRemoteRequest(uint8_t *data, size_t size); +} #endif // MONITORSERVICESTUB_FUZZER \ No newline at end of file diff --git a/test/fuzztest/monitor_fuzztest/monitorservicestub_fuzzer/project.xml b/test/fuzztest/monitor_fuzztest/monitorservicestub1_fuzzer/project.xml similarity index 97% rename from test/fuzztest/monitor_fuzztest/monitorservicestub_fuzzer/project.xml rename to test/fuzztest/monitor_fuzztest/monitorservicestub1_fuzzer/project.xml index 61d63a0715de022600b3ff9465d20223551325c8..7133b2b92440904a5ed04b838733acea0f97486a 100644 --- a/test/fuzztest/monitor_fuzztest/monitorservicestub_fuzzer/project.xml +++ b/test/fuzztest/monitor_fuzztest/monitorservicestub1_fuzzer/project.xml @@ -1,25 +1,25 @@ - - - - - - 1000 - - 300 - - 4096 - - + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/player_fuzztest/playerstub_fuzzer/BUILD.gn b/test/fuzztest/monitor_fuzztest/monitorservicestub2_fuzzer/BUILD.gn similarity index 63% rename from test/fuzztest/player_fuzztest/playerstub_fuzzer/BUILD.gn rename to test/fuzztest/monitor_fuzztest/monitorservicestub2_fuzzer/BUILD.gn index 9f5d404e66d1613c2e2ff8d4b364c266ae8a7c78..7e2b03e4c62f0c8d47cd1faf863606d53de4bfa7 100644 --- a/test/fuzztest/player_fuzztest/playerstub_fuzzer/BUILD.gn +++ b/test/fuzztest/monitor_fuzztest/monitorservicestub2_fuzzer/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2023 Huawei Device Co., Ltd. +# Copyright (c) 2024 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 @@ -15,22 +15,26 @@ import("//build/config/features.gni") import("//build/test.gni") import("//foundation/multimedia/player_framework/config.gni") -module_output_path = "$MODULE_OUTPUT_PATH/media_player" +MEDIA_ROOT_DIR = "//foundation/multimedia/player_framework/" ##############################fuzztest########################################## -ohos_fuzztest("PlayerStubFuzzTest") { - module_out_path = module_output_path +ohos_fuzztest("MonitorServiceStub2FuzzTest") { + module_out_path = "$MODULE_OUTPUT_PATH/monitor" fuzz_config_file = - "../../../../test/fuzztest/player_fuzztest/playerstub_fuzzer" + "$MEDIA_ROOT_DIR/test/fuzztest/monitor_fuzztest/monitorservicestub2_fuzzer" + resource_config_file = "$MEDIA_ROOT_DIR/test/fuzztest/resource/ohos_test.xml" include_dirs = [ - "../../../../services/services/player/ipc", + "$MEDIA_ROOT_DIR/interfaces/inner_api/native", + "$MEDIA_ROOT_DIR/services/utils/include", + "$MEDIA_ROOT_DIR/test/fuzztest/common/", + "$MEDIA_PLAYER_GRAPHIC/interfaces/innerkits/surface", + "../../../../services/services/monitor/ipc", "../../../../services/services/sa_media/ipc", "../../../../services/services/sa_media/server", "../../../../services/services/sa_media/server_manager", - "../../../../test/fuzztest/player_fuzztest", - "../../../../interfaces/inner_api/native", - "../../../../test/fuzztest/common", + "../../../../../media_foundation/interface/inner_api", + "../../../../../media_foundation/interface/inner_api/common", ] cflags = [ "-std=c++17", @@ -53,29 +57,25 @@ ohos_fuzztest("PlayerStubFuzzTest") { "-Wimplicit-fallthrough", "-Wsign-compare", "-Wunused-parameter", - "-DBINDER_IPC_32BIT", ] - if (player_framework_support_player) { + if (player_framework_support_monitor) { sources = [ "../../../../test/fuzztest/common/stub_common.cpp", - "player_service_proxy_fuzzer.cpp", - "playerstub_fuzzer.cpp", + "monitorservicestub2_fuzzer.cpp", ] } - deps = [ "../../../../services/services:media_service" ] + deps = [ + "../../../../services/services:media_service", + "../../../../services/utils:media_service_utils", + ] external_deps = [ "c_utils:utils", "graphic_surface:surface", "hilog:libhilog", "ipc:ipc_single", - "player_framework:media_client", "safwk:system_ability_fwk", "samgr:samgr_proxy", ] - if (player_framework_support_lowpower_av_sink) { - external_deps += [ - "drivers_interface_lpplayer:liblow_power_player_proxy_1.0", - ] - } + part_name = "player_framework" } diff --git a/test/fuzztest/player_fuzztest/playerservicestub_fuzzer/corpus/init b/test/fuzztest/monitor_fuzztest/monitorservicestub2_fuzzer/corpus/init similarity index 92% rename from test/fuzztest/player_fuzztest/playerservicestub_fuzzer/corpus/init rename to test/fuzztest/monitor_fuzztest/monitorservicestub2_fuzzer/corpus/init index 8eb5a7d6eb6b7d71f0c70c244e5768d62bee6ac5..6198079a28e860189d4294f6598f8ac6804c0dff 100644 --- a/test/fuzztest/player_fuzztest/playerservicestub_fuzzer/corpus/init +++ b/test/fuzztest/monitor_fuzztest/monitorservicestub2_fuzzer/corpus/init @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * Copyright (c) 2024 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/test/fuzztest/player_fuzztest/playerstub_fuzzer/playerstub_fuzzer.cpp b/test/fuzztest/monitor_fuzztest/monitorservicestub2_fuzzer/monitorservicestub2_fuzzer.cpp similarity index 43% rename from test/fuzztest/player_fuzztest/playerstub_fuzzer/playerstub_fuzzer.cpp rename to test/fuzztest/monitor_fuzztest/monitorservicestub2_fuzzer/monitorservicestub2_fuzzer.cpp index 49f003d16273948b86cb2af6ab50cca794db8c1b..61e1af5a212ed34415902759a07d9e96eaf6680c 100644 --- a/test/fuzztest/player_fuzztest/playerstub_fuzzer/playerstub_fuzzer.cpp +++ b/test/fuzztest/monitor_fuzztest/monitorservicestub2_fuzzer/monitorservicestub2_fuzzer.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Huawei Device Co., Ltd. + * Copyright (c) 2024 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 @@ -13,37 +13,34 @@ * limitations under the License. */ -#include "playerstub_fuzzer.h" +#include "monitorservicestub_fuzzer.h" +#include +#include +#include "string_ex.h" +#include "directory_ex.h" #include -#include "stub_common.h" #include "media_server.h" #include "media_parcel.h" -#include "i_standard_player_service.h" -#include "media_server_manager.h" +#include "i_standard_monitor_service.h" +#include "stub_common.h" + +using namespace std; +using namespace OHOS; +using namespace Media; namespace OHOS { namespace Media { -bool FuzzPlayerStub(uint8_t *data, size_t size) +MonitorServiceStubFuzzer::MonitorServiceStubFuzzer() +{ +} + +MonitorServiceStubFuzzer::~MonitorServiceStubFuzzer() { - if (data == nullptr || size < sizeof(int64_t)) { - return true; - } - sptr playerProxy = PlayerServiceProxyFuzzer::Create(); - if (playerProxy == nullptr) { - return false; - } - for (uint32_t codeId = 0; codeId < PlayerServiceProxyFuzzer::MAX_IPC_ID; codeId++) { - if (codeId != PlayerServiceProxyFuzzer::DESTROY) { - playerProxy->SendRequest(codeId, data, size, true); - } - } - playerProxy->SendRequest(PlayerServiceProxyFuzzer::DESTROY, data, size, false); - return true; } const int32_t SYSTEM_ABILITY_ID = 3002; const bool RUN_ON_CREATE = false; -bool FuzzPlayerStubLocal(uint8_t *data, size_t size) +bool MonitorServiceStubFuzzer::FuzzMonitorOnRemoteRequest(uint8_t *data, size_t size) { if (data == nullptr || size < sizeof(int64_t)) { return true; @@ -51,40 +48,48 @@ bool FuzzPlayerStubLocal(uint8_t *data, size_t size) std::shared_ptr mediaServer = std::make_shared(SYSTEM_ABILITY_ID, RUN_ON_CREATE); sptr listener = new(std::nothrow) MediaListenerStubFuzzer(); - sptr player = mediaServer->GetSubSystemAbility( - IStandardMediaService::MediaSystemAbility::MEDIA_PLAYER, listener); - if (player == nullptr) { + sptr monitor = mediaServer->GetSubSystemAbility( + IStandardMediaService::MediaSystemAbility::MEDIA_MONITOR, listener); + if (monitor == nullptr) { return false; } - sptr> playerStub = iface_cast>(player); - if (playerStub == nullptr) { + sptr> monitorStub = + iface_cast>(monitor); + if (monitorStub == nullptr) { return false; } - bool isWirteToken = size >0 && data[0] % 9 != 0; - for (uint32_t code = 0; code <= PlayerServiceProxyFuzzer::MAX_IPC_ID; code++) { - MessageParcel msg; - if (isWirteToken) { - msg.WriteInterfaceToken(playerStub->GetDescriptor()); - } - msg.WriteBuffer(data, size); - msg.RewindRead(0); - MessageParcel reply; - MessageOption option; - playerStub->OnRemoteRequest(code, msg, reply, option); - } - MediaServerManager::GetInstance().DestoryMemoryReportTask(); + uint32_t code = 1; + MessageParcel msg; + msg.WriteInterfaceToken(monitorStub->GetDescriptor()); + msg.WriteBuffer(data, size); + msg.RewindRead(0); + MessageParcel reply; + MessageOption option; + monitorStub->OnRemoteRequest(code, msg, reply, option); return true; } } + +bool FuzzTestMonitorOnRemoteRequest(uint8_t *data, size_t size) +{ + if (data == nullptr) { + return true; + } + + if (size < sizeof(int32_t)) { + return true; + } + MonitorServiceStubFuzzer testMonitor; + return testMonitor.FuzzMonitorOnRemoteRequest(data, size); +} } /* Fuzzer entry point */ extern "C" int LLVMFuzzerTestOneInput(uint8_t *data, size_t size) { /* Run your code on data */ - OHOS::Media::FuzzPlayerStub(data, size); - OHOS::Media::FuzzPlayerStubLocal(data, size); + OHOS::FuzzTestMonitorOnRemoteRequest(data, size); return 0; } \ No newline at end of file diff --git a/test/fuzztest/player_fuzztest/playerservicestub_fuzzer/playerservicestub_fuzzer.h b/test/fuzztest/monitor_fuzztest/monitorservicestub2_fuzzer/monitorservicestub_fuzzer.h similarity index 53% rename from test/fuzztest/player_fuzztest/playerservicestub_fuzzer/playerservicestub_fuzzer.h rename to test/fuzztest/monitor_fuzztest/monitorservicestub2_fuzzer/monitorservicestub_fuzzer.h index a5d6386b4ea356ac6fa2be2f0df06582ea8080e6..41dc6a3991889160d83bdf74910229bc05e52cc1 100644 --- a/test/fuzztest/player_fuzztest/playerservicestub_fuzzer/playerservicestub_fuzzer.h +++ b/test/fuzztest/monitor_fuzztest/monitorservicestub2_fuzzer/monitorservicestub_fuzzer.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * Copyright (c) 2024 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 @@ -13,22 +13,27 @@ * limitations under the License. */ -#ifndef PLAYERSERVICESTUB_FUZZER -#define PLAYERSERVICESTUB_FUZZER +#ifndef MONITORSERVICESTUB_FUZZER +#define MONITORSERVICESTUB_FUZZER -#define FUZZ_PROJECT_NAME "playerservicestub_fuzzer" -#include "i_standard_media_service.h" +#include +#include +#include +#include +#include +#include + +#define FUZZ_PROJECT_NAME "monitorservicestub_fuzzer" namespace OHOS { namespace Media { -class PlayerServiceStubFuzzer { +class MonitorServiceStubFuzzer { public: - PlayerServiceStubFuzzer(); - ~PlayerServiceStubFuzzer(); - bool FuzzServiceStub(uint8_t *data, size_t size); + MonitorServiceStubFuzzer(); + ~MonitorServiceStubFuzzer(); + bool FuzzMonitorOnRemoteRequest(uint8_t *data, size_t size); }; } -bool FuzzPlayerServiceStub(uint8_t *data, size_t size); +bool FuzzTestMonitorOnRemoteRequest(uint8_t *data, size_t size); } - -#endif // PLAYERSERVICESTUB_FUZZER +#endif // MONITORSERVICESTUB_FUZZER \ No newline at end of file diff --git a/test/fuzztest/player_fuzztest/playerstub_fuzzer/project.xml b/test/fuzztest/monitor_fuzztest/monitorservicestub2_fuzzer/project.xml similarity index 95% rename from test/fuzztest/player_fuzztest/playerstub_fuzzer/project.xml rename to test/fuzztest/monitor_fuzztest/monitorservicestub2_fuzzer/project.xml index 4fdbc407f205680885fa42663163b5c987f123a6..7133b2b92440904a5ed04b838733acea0f97486a 100644 --- a/test/fuzztest/player_fuzztest/playerstub_fuzzer/project.xml +++ b/test/fuzztest/monitor_fuzztest/monitorservicestub2_fuzzer/project.xml @@ -1,5 +1,5 @@ -