From f6a12b8059b1507fed12e9e023acd3775746cfc7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=BB=A1=E4=B8=9C=E5=B3=B0?= Date: Wed, 3 Sep 2025 16:57:10 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=B8=8D=E8=A7=84?= =?UTF-8?q?=E8=8C=83=E7=9A=84FUZZ=E7=94=A8=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 满东峰 --- .../BUILD.gn | 6 +- .../corpus/init | 30 +- .../monitorservicestub1_fuzzer.cpp} | 191 ++-- .../monitorservicestub_fuzzer.h | 76 +- .../project.xml | 50 +- .../monitorservicestub2_fuzzer}/BUILD.gn | 40 +- .../monitorservicestub2_fuzzer}/corpus/init | 2 +- .../monitorservicestub2_fuzzer.cpp} | 87 +- .../monitorservicestub_fuzzer.h} | 29 +- .../monitorservicestub2_fuzzer}/project.xml | 2 +- .../monitorservicestub3_fuzzer}/BUILD.gn | 45 +- .../monitorservicestub3_fuzzer}/corpus/init | 30 +- .../monitorservicestub3_fuzzer.cpp | 95 ++ .../monitorservicestub_fuzzer.h} | 26 +- .../monitorservicestub3_fuzzer}/project.xml | 2 +- .../playerapi_fuzzer/playerapi_fuzzer.cpp | 2 +- .../playerservicestub_fuzzer.cpp | 169 ---- .../player_service_proxy_fuzzer.cpp | 846 ------------------ .../player_service_proxy_fuzzer.h | 256 ------ 19 files changed, 417 insertions(+), 1567 deletions(-) rename test/fuzztest/monitor_fuzztest/{monitorservicestub_fuzzer => monitorservicestub1_fuzzer}/BUILD.gn (96%) rename test/fuzztest/monitor_fuzztest/{monitorservicestub_fuzzer => monitorservicestub1_fuzzer}/corpus/init (97%) rename test/fuzztest/monitor_fuzztest/{monitorservicestub_fuzzer/monitorservicestub_fuzzer.cpp => monitorservicestub1_fuzzer/monitorservicestub1_fuzzer.cpp} (83%) rename test/fuzztest/monitor_fuzztest/{monitorservicestub_fuzzer => monitorservicestub1_fuzzer}/monitorservicestub_fuzzer.h (96%) rename test/fuzztest/monitor_fuzztest/{monitorservicestub_fuzzer => monitorservicestub1_fuzzer}/project.xml (97%) rename test/fuzztest/{player_fuzztest/playerstub_fuzzer => monitor_fuzztest/monitorservicestub2_fuzzer}/BUILD.gn (63%) rename test/fuzztest/{player_fuzztest/playerservicestub_fuzzer => monitor_fuzztest/monitorservicestub2_fuzzer}/corpus/init (92%) rename test/fuzztest/{player_fuzztest/playerstub_fuzzer/playerstub_fuzzer.cpp => monitor_fuzztest/monitorservicestub2_fuzzer/monitorservicestub2_fuzzer.cpp} (43%) rename test/fuzztest/{player_fuzztest/playerservicestub_fuzzer/playerservicestub_fuzzer.h => monitor_fuzztest/monitorservicestub2_fuzzer/monitorservicestub_fuzzer.h} (53%) rename test/fuzztest/{player_fuzztest/playerstub_fuzzer => monitor_fuzztest/monitorservicestub2_fuzzer}/project.xml (95%) rename test/fuzztest/{player_fuzztest/playerservicestub_fuzzer => monitor_fuzztest/monitorservicestub3_fuzzer}/BUILD.gn (55%) rename test/fuzztest/{player_fuzztest/playerstub_fuzzer => monitor_fuzztest/monitorservicestub3_fuzzer}/corpus/init (90%) create mode 100644 test/fuzztest/monitor_fuzztest/monitorservicestub3_fuzzer/monitorservicestub3_fuzzer.cpp rename test/fuzztest/{player_fuzztest/playerstub_fuzzer/playerstub_fuzzer.h => monitor_fuzztest/monitorservicestub3_fuzzer/monitorservicestub_fuzzer.h} (52%) rename test/fuzztest/{player_fuzztest/playerservicestub_fuzzer => monitor_fuzztest/monitorservicestub3_fuzzer}/project.xml (95%) delete mode 100644 test/fuzztest/player_fuzztest/playerservicestub_fuzzer/playerservicestub_fuzzer.cpp delete mode 100644 test/fuzztest/player_fuzztest/playerstub_fuzzer/player_service_proxy_fuzzer.cpp delete mode 100644 test/fuzztest/player_fuzztest/playerstub_fuzzer/player_service_proxy_fuzzer.h 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 7e6e9d48e..45bc97e3e 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 d27c29f2d..6198079a2 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 9e29a54fa..fe63c19cc 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 e43476c5b..41dc6a399 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 61d63a071..7133b2b92 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 9f5d404e6..7e2b03e4c 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 8eb5a7d6e..6198079a2 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 49f003d16..61e1af5a2 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 a5d6386b4..41dc6a399 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 4fdbc407f..7133b2b92 100644 --- a/test/fuzztest/player_fuzztest/playerstub_fuzzer/project.xml +++ b/test/fuzztest/monitor_fuzztest/monitorservicestub2_fuzzer/project.xml @@ -1,5 +1,5 @@ -