From 4371957ad336c3f2daa2be6e23e108bb43c7b0e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=A1=8C=E5=A2=9E?= Date: Wed, 17 Jul 2024 11:06:43 +0800 Subject: [PATCH 1/2] build successfully. --- .vscode/settings.json | 85 +++++++++++++ application/AppScope/app.json | 4 +- application/AppScope/app.json5 | 4 +- .../main/resources/base/element/string.json | 2 +- .../main/resources/bo_CN/element/string.json | 6 +- .../mcc460-bo_CN/element/string.json | 4 +- .../resources/mcc460-en/element/string.json | 4 + .../resources/mcc460-ug/element/string.json | 4 +- .../mcc460-zh_CN/element/string.json | 4 + .../mcc460-zh_HK/element/string.json | 4 +- .../mcc460-zh_TW/element/string.json | 4 +- .../src/main/resources/ug/element/string.json | 6 +- .../main/resources/zh_CN/element/string.json | 6 +- .../main/resources/zh_HK/element/string.json | 6 +- .../main/resources/zh_TW/element/string.json | 6 +- .../main/resources/zz_ZX/element/string.json | 2 +- common/utils/include/constants.h | 5 + .../include/distributed_hardware_errno.h | 1 + .../src/distributed_hardware_fwk_kit.cpp | 12 ++ .../inner_kits/src/ipc/dhfwk_sa_manager.cpp | 8 ++ .../src/ipc/distributed_hardware_proxy.cpp | 14 ++- .../distributed_hardware_manager_factory.h | 4 +- .../src/componentloader/component_loader.cpp | 30 +++-- .../componentmanager/component_disable.cpp | 16 +++ .../src/componentmanager/component_enable.cpp | 16 +++ .../componentmanager/component_manager.cpp | 114 +++++++++++++++++- .../componentmanager/component_monitor.cpp | 5 + .../componentmanager/component_privacy.cpp | 22 +++- .../dh_data_sync_trigger_listener.cpp | 4 + .../componentmanager/dh_state_listener.cpp | 8 ++ .../src/distributed_hardware_manager.cpp | 24 ++++ .../distributed_hardware_manager_factory.cpp | 31 +++++ .../src/distributed_hardware_service.cpp | 12 ++ .../src/distributed_hardware_stub.cpp | 6 - .../src/hidumphelper/enabled_comps_dump.cpp | 20 +++ .../src/ipc/publisher_listener_proxy.cpp | 2 +- .../local_hardware_manager.cpp | 2 +- .../src/lowlatency/low_latency_listener.cpp | 6 +- .../src/publisher/publisher_item.cpp | 2 +- .../src/resourcemanager/capability_info.cpp | 16 +++ .../capability_info_manager.cpp | 74 +++++++++++- .../src/resourcemanager/capability_utils.cpp | 4 + .../src/resourcemanager/db_adapter.cpp | 48 +++++++- .../local_capability_info_manager.cpp | 34 +++++- .../resourcemanager/meta_capability_info.cpp | 12 ++ .../src/resourcemanager/meta_info_manager.cpp | 44 +++++++ .../src/resourcemanager/version_info.cpp | 16 +++ .../resourcemanager/version_info_manager.cpp | 24 ++++ .../src/task/offline_task.cpp | 11 +- .../src/transport/dh_comm_tool.cpp | 2 +- .../src/transport/dh_transport.cpp | 40 +++++- .../src/transport/dh_transport_obj.cpp | 20 +++ .../src/utils/dh_context.cpp | 63 +++++++++- .../src/versionmanager/version_manager.cpp | 16 +++ .../src/mock_hardware_handler.cpp | 10 ++ utils/src/anonymous_string.cpp | 7 +- utils/src/dh_utils_tool.cpp | 10 +- utils/src/histreamer_ability_parser.cpp | 105 ++++++++++++---- utils/src/histreamer_query_tool.cpp | 4 +- 59 files changed, 951 insertions(+), 124 deletions(-) create mode 100644 .vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 00000000..37120737 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,85 @@ +{ + "files.associations": { + "xstring": "cpp", + "algorithm": "cpp", + "array": "cpp", + "atomic": "cpp", + "bit": "cpp", + "cctype": "cpp", + "charconv": "cpp", + "chrono": "cpp", + "cinttypes": "cpp", + "clocale": "cpp", + "cmath": "cpp", + "compare": "cpp", + "concepts": "cpp", + "condition_variable": "cpp", + "cstddef": "cpp", + "cstdint": "cpp", + "cstdio": "cpp", + "cstdlib": "cpp", + "cstring": "cpp", + "ctime": "cpp", + "cwchar": "cpp", + "deque": "cpp", + "exception": "cpp", + "format": "cpp", + "forward_list": "cpp", + "fstream": "cpp", + "functional": "cpp", + "future": "cpp", + "initializer_list": "cpp", + "iomanip": "cpp", + "ios": "cpp", + "iosfwd": "cpp", + "iostream": "cpp", + "istream": "cpp", + "iterator": "cpp", + "limits": "cpp", + "list": "cpp", + "locale": "cpp", + "map": "cpp", + "memory": "cpp", + "mutex": "cpp", + "new": "cpp", + "optional": "cpp", + "ostream": "cpp", + "queue": "cpp", + "random": "cpp", + "ranges": "cpp", + "ratio": "cpp", + "set": "cpp", + "shared_mutex": "cpp", + "span": "cpp", + "sstream": "cpp", + "stdexcept": "cpp", + "stop_token": "cpp", + "streambuf": "cpp", + "string": "cpp", + "system_error": "cpp", + "thread": "cpp", + "tuple": "cpp", + "type_traits": "cpp", + "typeinfo": "cpp", + "unordered_map": "cpp", + "unordered_set": "cpp", + "utility": "cpp", + "vector": "cpp", + "xfacet": "cpp", + "xhash": "cpp", + "xiosbase": "cpp", + "xlocale": "cpp", + "xlocbuf": "cpp", + "xlocinfo": "cpp", + "xlocmes": "cpp", + "xlocmon": "cpp", + "xlocnum": "cpp", + "xloctime": "cpp", + "xmemory": "cpp", + "xtr1common": "cpp", + "xtree": "cpp", + "xutility": "cpp", + "coroutine": "cpp", + "resumable": "cpp" + } +} \ No newline at end of file diff --git a/application/AppScope/app.json b/application/AppScope/app.json index fab17e3b..fb5f8bdd 100644 --- a/application/AppScope/app.json +++ b/application/AppScope/app.json @@ -2,8 +2,8 @@ "app": { "bundleName": "com.ohos.dhardwareui", "vendor": "example", - "versionCode": 10000015, - "versionName": "1.0.15", + "versionCode": 10000013, + "versionName": "1.0.13", "icon": "$media:app_icon", "label": "$string:app_name", "minAPIVersion": 11, diff --git a/application/AppScope/app.json5 b/application/AppScope/app.json5 index 67ea3605..eb161cb4 100644 --- a/application/AppScope/app.json5 +++ b/application/AppScope/app.json5 @@ -16,8 +16,8 @@ "app": { "bundleName": "com.ohos.dhardwareui", "vendor": "example", - "versionCode": 10000015, - "versionName": "1.0.15", + "versionCode": 10000013, + "versionName": "1.0.13", "icon": "$media:app_icon", "label": "$string:app_name", "minAPIVersion": 11, diff --git a/application/entry/src/main/resources/base/element/string.json b/application/entry/src/main/resources/base/element/string.json index 86cc704f..36b755f0 100644 --- a/application/entry/src/main/resources/base/element/string.json +++ b/application/entry/src/main/resources/base/element/string.json @@ -54,7 +54,7 @@ }, { "name": "continue_desc", - "value":"Start viewing, editing, or streaming content on one device, then instantly continue on another device using the same HUAWEI ID." + "value":"Start something on one device, then pick it up on another. For example, you can start a note on your phone, then finish it on your tablet.\n\nTo use Continuity, devices need to be close together, using the same HUAWEI ID, and have Wi-Fi, Bluetooth, as well as this feature enabled." }, { "name": "multi_device_collaboration", diff --git a/application/entry/src/main/resources/bo_CN/element/string.json b/application/entry/src/main/resources/bo_CN/element/string.json index 8cc0f20b..6bd9656c 100644 --- a/application/entry/src/main/resources/bo_CN/element/string.json +++ b/application/entry/src/main/resources/bo_CN/element/string.json @@ -30,15 +30,11 @@ }, { "name":"continue_desc", - "value":"སྒྲིག་ཆས་གཅིག་གི་ཐོག་ཏུ་བཤར་ལྟ་དང་རྩོམ་སྒྲིག་བྱས་རྗེས། ཉེ་འགྲམ་གྱི་ཧྭ་ཝེ་ཐོ་ཨང་གཅིག་པ་ཐོ་འཇུག་བྱས་ཡོད་པའི་སྒྲིག་ཆས་གཞན་ཞིག་གི་ཐོག་ཏུ་མུ་མཐུད་བཀོལ་ཆོག" + "value":"སྒྲིག་ཆས་གཅིག་གི་ཐོག་ཏུ་བཤར་ལྟ་དང་རྩོམ་སྒྲིག་བྱས་རྗེས། ཉེ་འགྲམ་གྱི་ཧྭ་ཝེ་ཐོ་ཨང་གཅིག་པ་ཐོ་འཇུག་བྱས་ཡོད་པའི་སྒྲིག་ཆས་ཐོག་ཏུ་མུ་མཐུད་ཆོག རྩོལ་ནུས་འདི་བཀོལ་སྤྱོད་བྱ་བར་ཕྱོགས་གཉིས་པོས་༼འཕྲོ་མཐུད་༽ Wi-Fi དང་ སོ་སྔོན་ཁ་ཕྱེ་ནས་གནས་དགོས།" }, { "name":"continue_title", "value":"འཕྲོ་མཐུད།" - }, - { - "name":"continue_privacy_text", - "value":"ཞབས་ཞུ་འདི་བཀོལ་བའི་བརྒྱུད་རིམ་ཁྲོད་དུ་སོ་སྔོན་དང་ Wi-Fi རྩོལ་ནུས་བཀོལ་དགོས། སྒྲིག་ཆས་ཀྱི་མིང་ཀློག་ལེན་བྱས་ནས་འཕྲོ་མཐུད་བྱ་ཡུལ་གྱི་སྒྲིག་ཆས་ལ་བརྒྱུད་སྐྱེལ་བྱ། བསད་སྤར་ཁ་ཕྱེ་ཚེ། ཁྱེད་ཀྱིས་གོང་གི་ནང་དོན་ལ་མོས་མཐུན་བྱེད་པ་མཚོན།" } ] } \ No newline at end of file diff --git a/application/entry/src/main/resources/mcc460-bo_CN/element/string.json b/application/entry/src/main/resources/mcc460-bo_CN/element/string.json index cfe5c657..284cee98 100644 --- a/application/entry/src/main/resources/mcc460-bo_CN/element/string.json +++ b/application/entry/src/main/resources/mcc460-bo_CN/element/string.json @@ -1,8 +1,8 @@ { "string":[ { - "name":"continue_privacy_text", - "value":"ཞབས་ཞུ་འདི་བཀོལ་བའི་བརྒྱུད་རིམ་ཁྲོད་དུ་སོ་སྔོན་དང་ WLAN རྩོལ་ནུས་བཀོལ་དགོས། སྒྲིག་ཆས་ཀྱི་མིང་ཀློག་ལེན་བྱས་ནས་འཕྲོ་མཐུད་བྱ་ཡུལ་གྱི་སྒྲིག་ཆས་ལ་བརྒྱུད་སྐྱེལ་བྱ། བསད་སྤར་ཁ་ཕྱེ་ཚེ། ཁྱེད་ཀྱིས་གོང་གི་ནང་དོན་ལ་མོས་མཐུན་བྱེད་པ་མཚོན།" + "name":"continue_desc", + "value":"སྒྲིག་ཆས་གཅིག་གི་ཐོག་ཏུ་བཤར་ལྟ་དང་རྩོམ་སྒྲིག་བྱས་རྗེས། ཉེ་འགྲམ་གྱི་ཧྭ་ཝེ་ཐོ་ཨང་གཅིག་པ་ཐོ་འཇུག་བྱས་ཡོད་པའི་སྒྲིག་ཆས་ཐོག་ཏུ་མུ་མཐུད་ཆོག རྩོལ་ནུས་འདི་བཀོལ་སྤྱོད་བྱ་བར་ཕྱོགས་གཉིས་པོས་༼འཕྲོ་མཐུད་༽ WLAN དང་ སོ་སྔོན་ཁ་ཕྱེ་ནས་གནས་དགོས།" } ] } \ No newline at end of file diff --git a/application/entry/src/main/resources/mcc460-en/element/string.json b/application/entry/src/main/resources/mcc460-en/element/string.json index 95597723..bdf7d620 100644 --- a/application/entry/src/main/resources/mcc460-en/element/string.json +++ b/application/entry/src/main/resources/mcc460-en/element/string.json @@ -1,5 +1,9 @@ { "string":[ + { + "name":"continue_desc", + "value":"Start something on one device, then pick it up on another. For example, you can start a note on your phone, then finish it on your tablet.\n\nTo use Continuity, devices need to be close together, using the same HUAWEI ID, and have WLAN, Bluetooth, as well as this feature enabled." + }, { "name":"continue_privacy_text", "value":"This service uses Bluetooth and WLAN. During use, it will read this device's name and send it to devices you hop to. By turning this on, you agree to these terms." diff --git a/application/entry/src/main/resources/mcc460-ug/element/string.json b/application/entry/src/main/resources/mcc460-ug/element/string.json index 349e5b23..985e2152 100644 --- a/application/entry/src/main/resources/mcc460-ug/element/string.json +++ b/application/entry/src/main/resources/mcc460-ug/element/string.json @@ -1,8 +1,8 @@ { "string":[ { - "name":"continue_privacy_text", - "value":"بۇ مۇلازىمەت كۆكچىش ۋە WLAN ئىشلىتىدۇ؛ بۇ ئۈسكۈنىنىڭ نامىنى ئوقۇپ، ئۆتكۈزىدىغان ئۈسكۈنىگە يوللايدۇ. بۇ مۇلازىمەتنى ئاچسىڭىز، يۇقىرىقىلارغا قوشۇلغان بولىسىز." + "name":"continue_desc", + "value":"بىر ئۈسكۈنىدە كۆرۈۋاتقان ياكى تەھرىرلەۋاتقان ئىشنى ئەتراپتىكى ئوخشاش خۇاۋېي ھېسابىغا تىزىملاپ كىرگەن يەنە بىر ئۈسكۈنىدە داۋاملاشتۇرۇشقا بولىدۇ. ھەر ئىككى ئۈسكۈنىدە «ئۆتكۈزۈش»، WLAN ۋە كۆكچىش ئوچۇق بولۇشى كېرەك." } ] } \ No newline at end of file diff --git a/application/entry/src/main/resources/mcc460-zh_CN/element/string.json b/application/entry/src/main/resources/mcc460-zh_CN/element/string.json index c1f08d6f..90bdc6b1 100644 --- a/application/entry/src/main/resources/mcc460-zh_CN/element/string.json +++ b/application/entry/src/main/resources/mcc460-zh_CN/element/string.json @@ -1,5 +1,9 @@ { "string":[ + { + "name":"continue_desc", + "value":"在一台设备上进行浏览或编辑,然后可在附近另一台登录相同华为帐号的设备上继续。" + }, { "name":"continue_privacy_text", "value":"本服务使用过程中需要使用蓝牙和 WLAN 功能,读取并传送本设备名称到要接续的设备。打开开关,即表示您同意上述内容。" diff --git a/application/entry/src/main/resources/mcc460-zh_HK/element/string.json b/application/entry/src/main/resources/mcc460-zh_HK/element/string.json index 7019b5ec..2c7d4ff7 100644 --- a/application/entry/src/main/resources/mcc460-zh_HK/element/string.json +++ b/application/entry/src/main/resources/mcc460-zh_HK/element/string.json @@ -1,8 +1,8 @@ { "string":[ { - "name":"continue_privacy_text", - "value":"本服務在使用過程中需要使用藍牙和 WLAN 功能,讀取並傳輸本裝置名稱至要接續的裝置。開啟開關,即表示您同意上述內容。" + "name":"continue_desc", + "value":"在一部裝置上進行瀏覽或編輯,然後可在附近另一部登入相同華為帳戶的裝置上繼續。此功能需雙方裝置啟用「接續」、WLAN 和藍牙。" } ] } \ No newline at end of file diff --git a/application/entry/src/main/resources/mcc460-zh_TW/element/string.json b/application/entry/src/main/resources/mcc460-zh_TW/element/string.json index ff9729fe..5db7559e 100644 --- a/application/entry/src/main/resources/mcc460-zh_TW/element/string.json +++ b/application/entry/src/main/resources/mcc460-zh_TW/element/string.json @@ -1,8 +1,8 @@ { "string":[ { - "name":"continue_privacy_text", - "value":"本服務使用過程中需要使用藍牙和 WLAN 功能,讀取本裝置名稱並將其傳輸至要接續的裝置。若開啟開關,即表示您同意上述內容。" + "name":"continue_desc", + "value":"在一台裝置中瀏覽或編輯,然後可以在附近另一台登入相同華為 ID 的裝置中繼續。此功能需要兩台裝置皆已啟用「接續」、WLAN 和藍牙。" } ] } \ No newline at end of file diff --git a/application/entry/src/main/resources/ug/element/string.json b/application/entry/src/main/resources/ug/element/string.json index 36b5b81a..e73f05a9 100644 --- a/application/entry/src/main/resources/ug/element/string.json +++ b/application/entry/src/main/resources/ug/element/string.json @@ -30,15 +30,11 @@ }, { "name":"continue_desc", - "value":"بىر ئۈسكۈنىدە كۆرۈۋاتقان ياكى تەھرىرلەۋاتقان ئىشنى ئەتراپتىكى ئوخشاش خۇاۋېي ھېسابىغا تىزىملاپ كىرگەن يەنە بىر ئۈسكۈنىدە داۋاملاشتۇرۇشقا بولىدۇ." + "value":"بىر ئۈسكۈنىدە كۆرۈۋاتقان ياكى تەھرىرلەۋاتقان ئىشنى ئەتراپتىكى ئوخشاش خۇاۋېي ھېسابىغا تىزىملاپ كىرگەن يەنە بىر ئۈسكۈنىدە داۋاملاشتۇرۇشقا بولىدۇ. ھەر ئىككى ئۈسكۈنىدە «ئۆتكۈزۈش»، Wi-Fi ۋە كۆكچىش ئوچۇق بولۇشى كېرەك." }, { "name":"continue_title", "value":"ئۆتكۈزۈش" - }, - { - "name":"continue_privacy_text", - "value":"بۇ مۇلازىمەت كۆكچىش ۋە Wi-Fi ئىشلىتىدۇ؛ بۇ ئۈسكۈنىنىڭ نامىنى ئوقۇپ، ئۆتكۈزىدىغان ئۈسكۈنىگە يوللايدۇ. بۇ مۇلازىمەتنى ئاچسىڭىز، يۇقىرىقىلارغا قوشۇلغان بولىسىز." } ] } \ No newline at end of file diff --git a/application/entry/src/main/resources/zh_CN/element/string.json b/application/entry/src/main/resources/zh_CN/element/string.json index acaf472c..1bdfe014 100644 --- a/application/entry/src/main/resources/zh_CN/element/string.json +++ b/application/entry/src/main/resources/zh_CN/element/string.json @@ -54,11 +54,11 @@ }, { "name":"continue_desc", - "value":"在一台设备上浏览或编辑内容后,只需在附近的另一台已登录相同华为账号设备的桌面任务栏上找到接续图标并点击,即可继续操作。" + "value":"在一台设备上进行浏览或编辑,然后可在附近另一台登录相同华为帐号的设备上继续。" }, { - "name":"multi_device_collaboration", - "value":"多设备协同" + "name": "multi_device_collaboration", + "value": "多设备协同" }, { "name":"continue_privacy_text", diff --git a/application/entry/src/main/resources/zh_HK/element/string.json b/application/entry/src/main/resources/zh_HK/element/string.json index 48da7e1a..1a7562d8 100644 --- a/application/entry/src/main/resources/zh_HK/element/string.json +++ b/application/entry/src/main/resources/zh_HK/element/string.json @@ -30,15 +30,11 @@ }, { "name":"continue_desc", - "value":"在一部裝置上進行瀏覽或編輯,然後可以在附近另一部登入相同華為 ID 的裝置上繼續使用。" + "value":"在一部裝置上進行瀏覽或編輯,然後可在附近另一部登入相同華為帳戶的裝置上繼續。此功能需雙方裝置啟用「接續」、Wi-Fi 和藍牙。" }, { "name":"continue_title", "value":"接續" - }, - { - "name":"continue_privacy_text", - "value":"本服務在使用過程中需要使用藍牙和 Wi-Fi 功能,讀取並傳輸本裝置名稱至要接續的裝置。開啟開關,即表示您同意上述內容。" } ] } \ No newline at end of file diff --git a/application/entry/src/main/resources/zh_TW/element/string.json b/application/entry/src/main/resources/zh_TW/element/string.json index 761a0ac3..b7da129b 100644 --- a/application/entry/src/main/resources/zh_TW/element/string.json +++ b/application/entry/src/main/resources/zh_TW/element/string.json @@ -30,15 +30,11 @@ }, { "name":"continue_desc", - "value":"在一台裝置中瀏覽或編輯,然後可以在附近另一台登入相同華為 ID 的裝置中繼續使用。" + "value":"在一台裝置中瀏覽或編輯,然後可以在附近另一台登入相同華為 ID 的裝置中繼續。此功能需要兩台裝置皆已啟用「接續」、Wi-Fi 和藍牙。" }, { "name":"continue_title", "value":"接續" - }, - { - "name":"continue_privacy_text", - "value":"本服務使用過程中需要使用藍牙和 Wi-Fi 功能,讀取本裝置名稱並將其傳輸至要接續的裝置。若開啟開關,即表示您同意上述內容。" } ] } \ No newline at end of file diff --git a/application/entry/src/main/resources/zz_ZX/element/string.json b/application/entry/src/main/resources/zz_ZX/element/string.json index f86ba681..2db7afc7 100644 --- a/application/entry/src/main/resources/zz_ZX/element/string.json +++ b/application/entry/src/main/resources/zz_ZX/element/string.json @@ -42,7 +42,7 @@ }, { "name":"continue_desc", - "value":"[TS_921308]_Start viewing, editing, or streaming content on one device, then instantly continue on another device using the same HUAWEI ID." + "value":"[TS_921308]_Start something on one device, then pick it up on another. For example, you can start a note on your phone, then finish it on your tablet.\n\nTo use Continuity, devices need to be close together, using the same HUAWEI ID, and have Wi-Fi, Bluetooth, as well as this feature enabled." }, { "name":"ContinueSwitchAbility_label", diff --git a/common/utils/include/constants.h b/common/utils/include/constants.h index 5e2a6bea..52bd4b77 100644 --- a/common/utils/include/constants.h +++ b/common/utils/include/constants.h @@ -36,6 +36,11 @@ namespace DistributedHardware { constexpr int32_t MODE_ENABLE = 0; constexpr int32_t MODE_DISABLE = 1; constexpr uint32_t MAX_SWITCH_SIZE = 256; + constexpr uint32_t MAX_ROUND_SIZE = 1000; + constexpr uint32_t MAX_JSON_SIZE = 40 * 1024 * 1024; + constexpr uint32_t MAX_HASH_SIZE = 64; + constexpr uint32_t MAX_KEY_SIZE = 256; + const std::string LOW_LATENCY_KEY = "identity"; const std::u16string DHMS_STUB_INTERFACE_TOKEN = u"ohos.distributedhardware.accessToken"; const std::string APP_ID = "dtbhardware_manager_service"; diff --git a/common/utils/include/distributed_hardware_errno.h b/common/utils/include/distributed_hardware_errno.h index 998aba9e..5ae24d55 100644 --- a/common/utils/include/distributed_hardware_errno.h +++ b/common/utils/include/distributed_hardware_errno.h @@ -69,6 +69,7 @@ namespace DistributedHardware { constexpr int32_t ERR_DH_FWK_RESOURCE_CAPINFO_POINTER_NULL = -10414; constexpr int32_t ERR_DH_FWK_RESOURCE_RES_DB_DATA_INVALID = -10415; + /* DistributedHardwareManager errno, range: [-10500, -10599] */ constexpr int32_t ERR_DH_FWK_HARDWARE_MANAGER_DEVICE_REPEAT_ONLINE = -10500; constexpr int32_t ERR_DH_FWK_HARDWARE_MANAGER_DEVICE_REPEAT_OFFLINE = -10501; diff --git a/interfaces/inner_kits/src/distributed_hardware_fwk_kit.cpp b/interfaces/inner_kits/src/distributed_hardware_fwk_kit.cpp index 782e2dd5..1c794ad1 100644 --- a/interfaces/inner_kits/src/distributed_hardware_fwk_kit.cpp +++ b/interfaces/inner_kits/src/distributed_hardware_fwk_kit.cpp @@ -203,6 +203,10 @@ int32_t DistributedHardwareFwkKit::RegisterCtlCenterCallback(int32_t engineId, int32_t DistributedHardwareFwkKit::PauseDistributedHardware(DHType dhType, const std::string &networkId) { + if (networkId.empty() || networkId.length() > MAX_ID_LEN){ + DHLOGE("Network ID is invalid!"); + return ERR_DH_FWK_PARA_INVALID; + } DHLOGI("Pause distributed hardware dhType %{public}u, networkId %{public}s", (uint32_t)dhType, GetAnonyString(networkId).c_str()); @@ -217,6 +221,10 @@ int32_t DistributedHardwareFwkKit::PauseDistributedHardware(DHType dhType, const int32_t DistributedHardwareFwkKit::ResumeDistributedHardware(DHType dhType, const std::string &networkId) { + if (networkId.empty() || networkId.length() > MAX_ID_LEN){ + DHLOGE("Network ID is invalid!"); + return ERR_DH_FWK_PARA_INVALID; + } DHLOGI("Resume distributed hardware dhType %{public}u, networkId %{public}s", (uint32_t)dhType, GetAnonyString(networkId).c_str()); @@ -231,6 +239,10 @@ int32_t DistributedHardwareFwkKit::ResumeDistributedHardware(DHType dhType, cons int32_t DistributedHardwareFwkKit::StopDistributedHardware(DHType dhType, const std::string &networkId) { + if (networkId.empty() || networkId.length() > MAX_ID_LEN){ + DHLOGE("Network ID is invalid!"); + return ERR_DH_FWK_PARA_INVALID; + } DHLOGI("Stop distributed hardware dhType %{public}u, networkId %{public}s", (uint32_t)dhType, GetAnonyString(networkId).c_str()); diff --git a/interfaces/inner_kits/src/ipc/dhfwk_sa_manager.cpp b/interfaces/inner_kits/src/ipc/dhfwk_sa_manager.cpp index ae595b0a..c635c778 100644 --- a/interfaces/inner_kits/src/ipc/dhfwk_sa_manager.cpp +++ b/interfaces/inner_kits/src/ipc/dhfwk_sa_manager.cpp @@ -102,6 +102,10 @@ void DHFWKSAManager::RegisterSAStateCallback(DHFWKSAStateCb callback) void DHFWKSAManager::SystemAbilityListener::OnAddSystemAbility(int32_t systemAbilityId, const std::string &deviceId) { + if (deviceId.empty() || deviceId.length() > MAX_ID_LEN){ + DHLOGE("Device ID is invalid!"); + return; + } (void)deviceId; if (systemAbilityId != DISTRIBUTED_HARDWARE_SA_ID) { DHLOGW("Receive SA Start, but sa id is not DHFWK, id: %{public}" PRId32, systemAbilityId); @@ -123,6 +127,10 @@ void DHFWKSAManager::SystemAbilityListener::OnAddSystemAbility(int32_t systemAbi void DHFWKSAManager::SystemAbilityListener::OnRemoveSystemAbility(int32_t systemAbilityId, const std::string &deviceId) { + if (deviceId.empty() || deviceId.length() > MAX_ID_LEN){ + DHLOGE("Device ID is invalid!"); + return; + } (void)deviceId; if (systemAbilityId != DISTRIBUTED_HARDWARE_SA_ID) { DHLOGW("Receive SA Stop, but sa id is not DHFWK, id: %{public}" PRId32, systemAbilityId); diff --git a/interfaces/inner_kits/src/ipc/distributed_hardware_proxy.cpp b/interfaces/inner_kits/src/ipc/distributed_hardware_proxy.cpp index a1abe8eb..e8c88237 100644 --- a/interfaces/inner_kits/src/ipc/distributed_hardware_proxy.cpp +++ b/interfaces/inner_kits/src/ipc/distributed_hardware_proxy.cpp @@ -145,7 +145,7 @@ int32_t DistributedHardwareProxy::PublishMessage(const DHTopic topic, const std: return ERR_DH_FWK_PARA_INVALID; } if (msg.empty() || msg.size() > MAX_MESSAGE_LEN) { - DHLOGE("Msg is invalid"); + DHLOGE("Msg is invalid!"); return ERR_DH_FWK_SERVICE_MSG_INVALID; } @@ -416,6 +416,10 @@ int32_t DistributedHardwareProxy::NotifySourceRemoteSinkStarted(std::string &dev int32_t DistributedHardwareProxy::PauseDistributedHardware(DHType dhType, const std::string &networkId) { + if (networkId.empty() || networkId.length() > MAX_ID_LEN){ + DHLOGE("Network ID is invalid!"); + return ERR_DH_FWK_PARA_INVALID; + } sptr remote = Remote(); if (remote == nullptr) { DHLOGE("remote service is null"); @@ -451,6 +455,10 @@ int32_t DistributedHardwareProxy::PauseDistributedHardware(DHType dhType, const int32_t DistributedHardwareProxy::ResumeDistributedHardware(DHType dhType, const std::string &networkId) { + if (networkId.empty() || networkId.length() > MAX_ID_LEN){ + DHLOGE("Network ID is invalid!"); + return ERR_DH_FWK_PARA_INVALID; + } sptr remote = Remote(); if (remote == nullptr) { DHLOGE("remote service is null"); @@ -486,6 +494,10 @@ int32_t DistributedHardwareProxy::ResumeDistributedHardware(DHType dhType, const int32_t DistributedHardwareProxy::StopDistributedHardware(DHType dhType, const std::string &networkId) { + if (networkId.empty() || networkId.length() > MAX_ID_LEN){ + DHLOGE("Network ID is invalid!"); + return ERR_DH_FWK_PARA_INVALID; + } sptr remote = Remote(); if (remote == nullptr) { DHLOGE("remote service is null"); diff --git a/services/distributedhardwarefwkservice/include/distributed_hardware_manager_factory.h b/services/distributedhardwarefwkservice/include/distributed_hardware_manager_factory.h index 3af91f36..b03c0219 100644 --- a/services/distributedhardwarefwkservice/include/distributed_hardware_manager_factory.h +++ b/services/distributedhardwarefwkservice/include/distributed_hardware_manager_factory.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2024 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 @@ -38,10 +38,10 @@ public: int32_t GetComponentVersion(std::unordered_map &versionMap); int Dump(const std::vector &argsStr, std::string &result); - void UnInit(); private: bool Init(); + void UnInit(); void CheckExitSAOrNot(); void ExitDHFWK(); diff --git a/services/distributedhardwarefwkservice/src/componentloader/component_loader.cpp b/services/distributedhardwarefwkservice/src/componentloader/component_loader.cpp index 9f65636e..b08b2947 100644 --- a/services/distributedhardwarefwkservice/src/componentloader/component_loader.cpp +++ b/services/distributedhardwarefwkservice/src/componentloader/component_loader.cpp @@ -115,22 +115,22 @@ std::vector ComponentLoader::GetAllCompTypes() int32_t ParseComponent(const cJSON *json, CompConfig &cfg) { if (!IsString(json, COMP_NAME)) { - DHLOGE("COMP_NAME is invalid"); + DHLOGE("COMP_NAME is invalid!"); return ERR_DH_FWK_JSON_PARSE_FAILED; } cfg.name = cJSON_GetObjectItem(json, COMP_NAME.c_str())->valuestring; if (!IsString(json, COMP_TYPE)) { - DHLOGE("COMP_TYPE is invalid"); + DHLOGE("COMP_TYPE is invalid!"); return ERR_DH_FWK_JSON_PARSE_FAILED; } cfg.type = g_mapDhTypeName[cJSON_GetObjectItem(json, COMP_TYPE.c_str())->valuestring]; if (!IsString(json, COMP_HANDLER_LOC)) { - DHLOGE("COMP_HANDLER_LOC is invalid"); + DHLOGE("COMP_HANDLER_LOC is invalid!"); return ERR_DH_FWK_JSON_PARSE_FAILED; } cfg.compHandlerLoc = cJSON_GetObjectItem(json, COMP_HANDLER_LOC.c_str())->valuestring; if (!IsString(json, COMP_HANDLER_VERSION)) { - DHLOGE("COMP_HANDLER_VERSION is invalid"); + DHLOGE("COMP_HANDLER_VERSION is invalid!"); return ERR_DH_FWK_JSON_PARSE_FAILED; } cfg.compHandlerVersion = cJSON_GetObjectItem(json, COMP_HANDLER_VERSION.c_str())->valuestring; @@ -140,17 +140,17 @@ int32_t ParseComponent(const cJSON *json, CompConfig &cfg) int32_t ParseSource(const cJSON *json, CompConfig &cfg) { if (!IsString(json, COMP_SOURCE_LOC)) { - DHLOGE("COMP_SOURCE_LOC is invalid"); + DHLOGE("COMP_SOURCE_LOC is invalid!"); return ERR_DH_FWK_JSON_PARSE_FAILED; } cfg.compSourceLoc = cJSON_GetObjectItem(json, COMP_SOURCE_LOC.c_str())->valuestring; if (!IsString(json, COMP_SOURCE_VERSION)) { - DHLOGE("COMP_SOURCE_VERSION is invalid"); + DHLOGE("COMP_SOURCE_VERSION is invalid!"); return ERR_DH_FWK_JSON_PARSE_FAILED; } cfg.compSourceVersion = cJSON_GetObjectItem(json, COMP_SOURCE_VERSION.c_str())->valuestring; if (!IsInt32(json, COMP_SOURCE_SA_ID)) { - DHLOGE("COMP_SOURCE_SA_ID is invalid"); + DHLOGE("COMP_SOURCE_SA_ID is invalid!"); return ERR_DH_FWK_JSON_PARSE_FAILED; } cfg.compSourceSaId = static_cast(cJSON_GetObjectItem(json, COMP_SOURCE_SA_ID.c_str())->valuedouble); @@ -160,17 +160,17 @@ int32_t ParseSource(const cJSON *json, CompConfig &cfg) int32_t ParseSink(const cJSON *json, CompConfig &cfg) { if (!IsString(json, COMP_SINK_LOC)) { - DHLOGE("COMP_SINK_LOC is invalid"); + DHLOGE("COMP_SINK_LOC is invalid!"); return ERR_DH_FWK_JSON_PARSE_FAILED; } cfg.compSinkLoc = cJSON_GetObjectItem(json, COMP_SINK_LOC.c_str())->valuestring; if (!IsString(json, COMP_SINK_VERSION)) { - DHLOGE("COMP_SINK_VERSION is invalid"); + DHLOGE("COMP_SINK_VERSION is invalid!"); return ERR_DH_FWK_JSON_PARSE_FAILED; } cfg.compSinkVersion = cJSON_GetObjectItem(json, COMP_SINK_VERSION.c_str())->valuestring; if (!IsInt32(json, COMP_SINK_SA_ID)) { - DHLOGE("COMP_SINK_SA_ID is invalid"); + DHLOGE("COMP_SINK_SA_ID is invalid!"); return ERR_DH_FWK_JSON_PARSE_FAILED; } cfg.compSinkSaId = static_cast(cJSON_GetObjectItem(json, COMP_SINK_SA_ID.c_str())->valuedouble); @@ -180,7 +180,7 @@ int32_t ParseSink(const cJSON *json, CompConfig &cfg) int32_t ParseResourceDesc(const cJSON *json, CompConfig &cfg) { if (!IsArray(json, COMP_RESOURCE_DESC)) { - DHLOGE("COMP_RESOURCE_DESC is invalid"); + DHLOGE("COMP_RESOURCE_DESC is invalid!"); return ERR_DH_FWK_JSON_PARSE_FAILED; } cJSON *resourceDescArray = cJSON_GetObjectItem(json, COMP_RESOURCE_DESC.c_str()); @@ -188,7 +188,7 @@ int32_t ParseResourceDesc(const cJSON *json, CompConfig &cfg) cJSON_ArrayForEach(element, resourceDescArray) { ResourceDesc desc; if (!IsString(element, COMP_SUBTYPE)) { - DHLOGE("COMP_SUBTYPE is invalid"); + DHLOGE("COMP_SUBTYPE is invalid!"); return ERR_DH_FWK_JSON_PARSE_FAILED; } desc.subtype = cJSON_GetObjectItem(element, COMP_SUBTYPE.c_str())->valuestring; @@ -252,6 +252,10 @@ bool ComponentLoader::CheckComponentEnable(const CompConfig &config) int32_t ComponentLoader::GetCompPathAndVersion(const std::string &jsonStr, std::map &dhtypeMap) { + if (jsonStr.empty() || jsonStr.length() > MAX_JSON_SIZE){ + DHLOGE("Json string is invalid!"); + return ERR_DH_FWK_PARA_INVALID; + } cJSON *root = cJSON_Parse(jsonStr.c_str()); if (root == NULL) { DHLOGE("jsonStr parse failed"); @@ -336,7 +340,7 @@ void ComponentLoader::ParseResourceDescFromJson(cJSON *resourceDescs, CompConfig } ResourceDesc resource; if (!IsString(resourceDesc, COMP_SUBTYPE)) { - DHLOGE("COMP_SUBTYPE is invalid"); + DHLOGE("COMP_SUBTYPE is invalid!"); return; } resource.subtype = cJSON_GetObjectItem(resourceDesc, COMP_SUBTYPE.c_str())->valuestring; diff --git a/services/distributedhardwarefwkservice/src/componentmanager/component_disable.cpp b/services/distributedhardwarefwkservice/src/componentmanager/component_disable.cpp index c70b14cd..bf658982 100644 --- a/services/distributedhardwarefwkservice/src/componentmanager/component_disable.cpp +++ b/services/distributedhardwarefwkservice/src/componentmanager/component_disable.cpp @@ -33,6 +33,14 @@ ComponentDisable::~ComponentDisable() {} int32_t ComponentDisable::Disable(const std::string &networkId, const std::string &dhId, IDistributedHardwareSource *handler) { + if (networkId.empty() || networkId.length() > MAX_ID_LEN){ + DHLOGE("Network ID is invalid!"); + return ERR_DH_FWK_PARA_INVALID; + } + if (dhId.empty() || dhId.length() > MAX_ID_LEN){ + DHLOGE("DHID is invalide!"); + return ERR_DH_FWK_PARA_INVALID; + } DHLOGD("networkId = %{public}s dhId = %{public}s.", GetAnonyString(networkId).c_str(), GetAnonyString(dhId).c_str()); if (handler == nullptr) { @@ -68,6 +76,14 @@ int32_t ComponentDisable::Disable(const std::string &networkId, const std::strin int32_t ComponentDisable::OnUnregisterResult(const std::string &networkId, const std::string &dhId, int32_t status, const std::string &data) { + if (networkId.empty() || networkId.length() > MAX_ID_LEN){ + DHLOGE("Network ID is invalid!"); + return ERR_DH_FWK_PARA_INVALID; + } + if (dhId.empty() || dhId.length() > MAX_ID_LEN){ + DHLOGE("DHID is invalide!"); + return ERR_DH_FWK_PARA_INVALID; + } if (status == DH_FWK_SUCCESS) { DHLOGI("disable success, networkId = %{public}s, dhId = %{public}s.", GetAnonyString(networkId).c_str(), GetAnonyString(dhId).c_str()); diff --git a/services/distributedhardwarefwkservice/src/componentmanager/component_enable.cpp b/services/distributedhardwarefwkservice/src/componentmanager/component_enable.cpp index d0f757b0..71794650 100644 --- a/services/distributedhardwarefwkservice/src/componentmanager/component_enable.cpp +++ b/services/distributedhardwarefwkservice/src/componentmanager/component_enable.cpp @@ -33,6 +33,14 @@ ComponentEnable::~ComponentEnable() {} int32_t ComponentEnable::Enable(const std::string &networkId, const std::string &dhId, const EnableParam ¶m, IDistributedHardwareSource *handler) { + if (networkId.empty() || networkId.length() > MAX_ID_LEN){ + DHLOGE("Network ID is invalid!"); + return ERR_DH_FWK_PARA_INVALID; + } + if (dhId.empty() || dhId.length() > MAX_ID_LEN){ + DHLOGE("DHID is invalide!"); + return ERR_DH_FWK_PARA_INVALID; + } DHLOGD("networkId = %{public}s dhId = %{public}s.", GetAnonyString(networkId).c_str(), GetAnonyString(dhId).c_str()); if (handler == nullptr) { @@ -68,6 +76,14 @@ int32_t ComponentEnable::Enable(const std::string &networkId, const std::string int32_t ComponentEnable::OnRegisterResult(const std::string &networkId, const std::string &dhId, int32_t status, const std::string &data) { + if (networkId.empty() || networkId.length() > MAX_ID_LEN){ + DHLOGE("Network ID is invalid!"); + return ERR_DH_FWK_PARA_INVALID; + } + if (dhId.empty() || dhId.length() > MAX_ID_LEN){ + DHLOGE("DHID is invalide!"); + return ERR_DH_FWK_PARA_INVALID; + } if (status == DH_FWK_SUCCESS) { DHLOGI("enable success, networkId = %{public}s, dhId = %{public}s.", GetAnonyString(networkId).c_str(), GetAnonyString(dhId).c_str()); diff --git a/services/distributedhardwarefwkservice/src/componentmanager/component_manager.cpp b/services/distributedhardwarefwkservice/src/componentmanager/component_manager.cpp index 525268eb..42e195c5 100644 --- a/services/distributedhardwarefwkservice/src/componentmanager/component_manager.cpp +++ b/services/distributedhardwarefwkservice/src/componentmanager/component_manager.cpp @@ -516,6 +516,18 @@ bool ComponentManager::InitCompSink() int32_t ComponentManager::Enable(const std::string &networkId, const std::string &uuid, const std::string &dhId, const DHType dhType) { + if (uuid.empty() || uuid.length() > MAX_ID_LEN){ + DHLOGE("UUID is invalid!"); + return ERR_DH_FWK_PARA_INVALID; + } + if (networkId.empty() || networkId.length() > MAX_ID_LEN){ + DHLOGE("Network ID is invalid!"); + return ERR_DH_FWK_PARA_INVALID; + } + if (dhId.empty() || dhId.length() > MAX_ID_LEN){ + DHLOGE("DHID is invalide!"); + return ERR_DH_FWK_PARA_INVALID; + } DHLOGI("start."); auto find = compSource_.find(dhType); if (find == compSource_.end()) { @@ -571,6 +583,18 @@ int32_t ComponentManager::Enable(const std::string &networkId, const std::string int32_t ComponentManager::RetryGetEnableParam(const std::string &networkId, const std::string &uuid, const std::string &dhId, const DHType dhType, EnableParam ¶m) { + if (networkId.empty() || networkId.length() > MAX_ID_LEN){ + DHLOGE("Network ID is invalid!"); + return ERR_DH_FWK_PARA_INVALID; + } + if (dhId.empty() || dhId.length() > MAX_ID_LEN){ + DHLOGE("DHID is invalide!"); + return ERR_DH_FWK_PARA_INVALID; + } + if (uuid.empty() || uuid.length() > MAX_ID_LEN){ + DHLOGE("UUID is invalid!"); + return ERR_DH_FWK_PARA_INVALID; + } for (int32_t retryCount = 0; retryCount < ENABLE_RETRY_MAX_TIMES; retryCount++) { if (!DHContext::GetInstance().IsDeviceOnline(uuid)) { DHLOGE("device is already offline, no need try GetEnableParam, uuid = %{public}s", @@ -590,6 +614,18 @@ int32_t ComponentManager::RetryGetEnableParam(const std::string &networkId, cons int32_t ComponentManager::Disable(const std::string &networkId, const std::string &uuid, const std::string &dhId, const DHType dhType) { + if (networkId.empty() || networkId.length() > MAX_ID_LEN){ + DHLOGE("Network ID is invalid!"); + return ERR_DH_FWK_PARA_INVALID; + } + if (dhId.empty() || dhId.length() > MAX_ID_LEN){ + DHLOGE("DHID is invalide!"); + return ERR_DH_FWK_PARA_INVALID; + } + if (uuid.empty() || uuid.length() > MAX_ID_LEN){ + DHLOGE("UUID is invalid!"); + return ERR_DH_FWK_PARA_INVALID; + } auto find = compSource_.find(dhType); if (find == compSource_.end()) { DHLOGE("can not find handler for dhId = %{public}s.", GetAnonyString(dhId).c_str()); @@ -636,6 +672,14 @@ DHType ComponentManager::GetDHType(const std::string &uuid, const std::string &d int32_t ComponentManager::GetEnableCapParam(const std::string &networkId, const std::string &uuid, DHType dhType, EnableParam ¶m, std::shared_ptr &capability) { + if (networkId.empty() || networkId.length() > MAX_ID_LEN){ + DHLOGE("Network ID is invalid!"); + return ERR_DH_FWK_PARA_INVALID; + } + if ( uuid.empty() || uuid.length() > MAX_ID_LEN ){ + DHLOGE("UUID is invalid!"); + return ERR_DH_FWK_PARA_INVALID; + } DeviceInfo sourceDeviceInfo = GetLocalDeviceInfo(); std::vector> sourceCapInfos; std::string sourceDHId; @@ -682,6 +726,14 @@ int32_t ComponentManager::GetEnableCapParam(const std::string &networkId, const int32_t ComponentManager::GetEnableMetaParam(const std::string &networkId, const std::string &uuid, DHType dhType, EnableParam ¶m, std::shared_ptr &metaCapPtr) { + if (networkId.empty() || networkId.length() > MAX_ID_LEN){ + DHLOGE("Network ID is invalid!"); + return ERR_DH_FWK_PARA_INVALID; + } + if ( uuid.empty() || uuid.length() > MAX_ID_LEN ){ + DHLOGE("UUID is invalid!"); + return ERR_DH_FWK_PARA_INVALID; + } DeviceInfo sourceDeviceInfo = GetLocalDeviceInfo(); std::vector> sourceMetaInfos; std::string sourceDHId; @@ -714,6 +766,14 @@ int32_t ComponentManager::GetEnableMetaParam(const std::string &networkId, const int32_t ComponentManager::GetCapParam(const std::string &uuid, const std::string &dhId, std::shared_ptr &capability) { + if (dhId.empty() || dhId.length() > MAX_ID_LEN){ + DHLOGE("DHID is invalide!"); + return ERR_DH_FWK_PARA_INVALID; + } + if ( uuid.empty() || uuid.length() > MAX_ID_LEN ){ + DHLOGE("UUID is invalid!"); + return ERR_DH_FWK_PARA_INVALID; + } std::string deviceId = GetDeviceIdByUUID(uuid); auto ret = CapabilityInfoManager::GetInstance()->GetCapability(deviceId, dhId, capability); if ((ret == DH_FWK_SUCCESS) && (capability != nullptr)) { @@ -735,6 +795,14 @@ int32_t ComponentManager::GetCapParam(const std::string &uuid, const std::string int32_t ComponentManager::GetMetaParam(const std::string &uuid, const std::string &dhId, std::shared_ptr &metaCapPtr) { + if (dhId.empty() || dhId.length() > MAX_ID_LEN){ + DHLOGE("DHID is invalide!"); + return ERR_DH_FWK_PARA_INVALID; + } + if ( uuid.empty() || uuid.length() > MAX_ID_LEN ){ + DHLOGE("UUID is invalid!"); + return ERR_DH_FWK_PARA_INVALID; + } auto ret = MetaInfoManager::GetInstance()->GetMetaCapInfo(DHContext::GetInstance().GetUdidHashIdByUUID(uuid), dhId, metaCapPtr); if ((ret == DH_FWK_SUCCESS) && (metaCapPtr != nullptr)) { @@ -748,6 +816,18 @@ int32_t ComponentManager::GetMetaParam(const std::string &uuid, const std::strin int32_t ComponentManager::GetEnableParam(const std::string &networkId, const std::string &uuid, const std::string &dhId, DHType dhType, EnableParam ¶m) { + if (networkId.empty() || networkId.length() > MAX_ID_LEN){ + DHLOGE("Network ID is invalid!"); + return ERR_DH_FWK_PARA_INVALID; + } + if (dhId.empty() || dhId.length() > MAX_ID_LEN){ + DHLOGE("DHID is invalide!"); + return ERR_DH_FWK_PARA_INVALID; + } + if ( uuid.empty() || uuid.length() > MAX_ID_LEN ){ + DHLOGE("UUID is invalid!"); + return ERR_DH_FWK_PARA_INVALID; + } DHLOGI("GetEnableParam start, networkId= %{public}s, uuid = %{public}s, dhId = %{public}s, dhType = %{public}#X,", GetAnonyString(networkId).c_str(), GetAnonyString(uuid).c_str(), GetAnonyString(dhId).c_str(), dhType); std::shared_ptr capability = nullptr; @@ -774,6 +854,10 @@ int32_t ComponentManager::GetEnableParam(const std::string &networkId, const std int32_t ComponentManager::GetVersionFromVerMgr(const std::string &uuid, const DHType dhType, std::string &version, bool isSink) { + if ( uuid.empty() || uuid.length() > MAX_ID_LEN ){ + DHLOGE("UUID is invalid!"); + return ERR_DH_FWK_PARA_INVALID; + } CompVersion compversion; int32_t ret = VersionManager::GetInstance().GetCompVersion(uuid, dhType, compversion); if (ret != DH_FWK_SUCCESS) { @@ -791,6 +875,10 @@ int32_t ComponentManager::GetVersionFromVerMgr(const std::string &uuid, const DH int32_t ComponentManager::GetVersionFromVerInfoMgr(const std::string &uuid, const DHType dhType, std::string &version, bool isSink) { + if ( uuid.empty() || uuid.length() > MAX_ID_LEN ){ + DHLOGE("UUID is invalid!"); + return ERR_DH_FWK_PARA_INVALID; + } VersionInfo versionInfo; int32_t ret = VersionInfoManager::GetInstance()->GetVersionInfoByDeviceId(GetDeviceIdByUUID(uuid), versionInfo); if (ret != DH_FWK_SUCCESS) { @@ -813,6 +901,10 @@ int32_t ComponentManager::GetVersionFromVerInfoMgr(const std::string &uuid, cons int32_t ComponentManager::GetVersion(const std::string &uuid, DHType dhType, std::string &version, bool isSink) { + if ( uuid.empty() || uuid.length() > MAX_ID_LEN ){ + DHLOGE("UUID is invalid!"); + return ERR_DH_FWK_PARA_INVALID; + } int32_t ret = GetVersionFromVerMgr(uuid, dhType, version, isSink); if ((ret == DH_FWK_SUCCESS) && (!version.empty())) { return DH_FWK_SUCCESS; @@ -828,6 +920,10 @@ int32_t ComponentManager::GetVersion(const std::string &uuid, DHType dhType, std void ComponentManager::UpdateVersionCache(const std::string &uuid, const VersionInfo &versionInfo) { + if ( uuid.empty() || uuid.length() > MAX_ID_LEN ){ + DHLOGE("UUID is invalid!"); + return; + } DHVersion dhVersion; dhVersion.uuid = uuid; dhVersion.dhVersion = versionInfo.dhVersion; @@ -914,6 +1010,10 @@ std::map ComponentManager::GetDHSinkInstance( bool ComponentManager::IsIdenticalAccount(const std::string &networkId) { + if (networkId.empty() || networkId.length() > MAX_ID_LEN){ + DHLOGE("Network ID is invalid!"); + return false; + } DmAuthForm authForm = DmAuthForm::INVALID_TYPE; std::vector deviceList; DeviceManager::GetInstance().GetTrustedDeviceList(DH_FWK_PKG_NAME, "", deviceList); @@ -935,6 +1035,14 @@ bool ComponentManager::IsIdenticalAccount(const std::string &networkId) void ComponentManager::UpdateBusinessState(const std::string &networkId, const std::string &dhId, BusinessState state) { + if (networkId.empty() || networkId.length() > MAX_ID_LEN){ + DHLOGE("Network ID is invalid!"); + return; + } + if (dhId.empty() || dhId.length() > MAX_ID_LEN){ + DHLOGE("DHID is invalide!"); + return; + } DHLOGI("UpdateBusinessState, networkId: %{public}s, dhId: %{public}s, state: %{public}" PRIu32, GetAnonyString(networkId).c_str(), GetAnonyString(dhId).c_str(), (uint32_t)state); { @@ -967,6 +1075,10 @@ BusinessState ComponentManager::QueryBusinessState(const std::string &uuid, cons void ComponentManager::TriggerFullCapsSync(const std::string &networkId) { + if (networkId.empty() || networkId.length() > MAX_ID_LEN){ + DHLOGE("Network ID is invalid!"); + return; + } if (networkId.empty()) { DHLOGE("Remote networkid is null"); return; @@ -1007,7 +1119,7 @@ void ComponentManager::ComponentManagerEventHandler::ProcessEvent( // do muanul sync with remote auto sharedObjPtr = event->GetSharedObject(); if (sharedObjPtr == nullptr) { - DHLOGE("The data sync param invalid"); + DHLOGE("The data sync param invalid!"); break; } std::string networkId = *sharedObjPtr; diff --git a/services/distributedhardwarefwkservice/src/componentmanager/component_monitor.cpp b/services/distributedhardwarefwkservice/src/componentmanager/component_monitor.cpp index fdcd7026..eac57f63 100644 --- a/services/distributedhardwarefwkservice/src/componentmanager/component_monitor.cpp +++ b/services/distributedhardwarefwkservice/src/componentmanager/component_monitor.cpp @@ -25,6 +25,7 @@ #include "component_loader.h" #include "component_manager.h" #include "device_type.h" +#include "constants.h" #include "distributed_hardware_errno.h" #include "distributed_hardware_log.h" @@ -47,6 +48,10 @@ ComponentMonitor::~ComponentMonitor() void ComponentMonitor::CompSystemAbilityListener::OnAddSystemAbility(int32_t saId, const std::string &deviceId) { + if (deviceId.empty() || deviceId.length() > MAX_ID_LEN){ + DHLOGE("Device ID is invalid!"); + return; + } DHLOGI("OnAddSystemAbility, saId: %{public}d, deviceId: %{public}s", saId, GetAnonyString(deviceId).c_str()); } diff --git a/services/distributedhardwarefwkservice/src/componentmanager/component_privacy.cpp b/services/distributedhardwarefwkservice/src/componentmanager/component_privacy.cpp index 6e836376..2bb33b6f 100644 --- a/services/distributedhardwarefwkservice/src/componentmanager/component_privacy.cpp +++ b/services/distributedhardwarefwkservice/src/componentmanager/component_privacy.cpp @@ -47,6 +47,10 @@ ComponentPrivacy::~ComponentPrivacy() int32_t ComponentPrivacy::OnPrivaceResourceMessage(const ResourceEventType &type, const std::string &subtype, const std::string &networkId, bool &isSensitive, bool &isSameAccout) { + if (networkId.empty() || networkId.length() > MAX_ID_LEN){ + DHLOGE("Network ID is invalid!"); + return ERR_DH_FWK_PARA_INVALID; + } DHLOGI("OnPrivaceResourceMessage start."); int32_t ret = DH_FWK_SUCCESS; if (type == ResourceEventType::EVENT_TYPE_QUERY_RESOURCE) { @@ -61,6 +65,10 @@ int32_t ComponentPrivacy::OnPrivaceResourceMessage(const ResourceEventType &type void ComponentPrivacy::HandlePullUpPage(const std::string &subtype, const std::string &networkId) { + if (networkId.empty() || networkId.length() > MAX_ID_LEN){ + DHLOGE("Network ID is invalid!"); + return; + } cJSON *jsonArrayMsg = cJSON_CreateArray(); if (jsonArrayMsg == NULL) { DHLOGE("Failed to create cJSON arrary."); @@ -119,6 +127,10 @@ void ComponentPrivacy::HandleClosePage(const std::string &subtype) int32_t ComponentPrivacy::OnResourceInfoCallback(const std::string &subtype, const std::string &networkId, bool &isSensitive, bool &isSameAccout) { + if (networkId.empty() || networkId.length() > MAX_ID_LEN){ + DHLOGE("Network ID is invalid!"); + return ERR_DH_FWK_PARA_INVALID; + } DHLOGI("OnResourceInfoCallback start."); std::map resourceDesc = ComponentLoader::GetInstance().GetCompResourceDesc(); if (resourceDesc.find(subtype) == resourceDesc.end()) { @@ -149,6 +161,10 @@ int32_t ComponentPrivacy::OnResourceInfoCallback(const std::string &subtype, con int32_t ComponentPrivacy::StartPrivacePage(const std::string &subtype, const std::string &networkId) { + if (networkId.empty() || networkId.length() > MAX_ID_LEN){ + DHLOGE("Network ID is invalid!"); + return ERR_DH_FWK_PARA_INVALID; + } DHLOGI("StartPrivacePage start."); DmDeviceInfo deviceInfo; DeviceManager::GetInstance().GetDeviceInfo(DH_FWK_PKG_NAME, networkId, deviceInfo); @@ -285,12 +301,12 @@ void ComponentPrivacy::ComponentEventHandler::ProcessStartPage(const AppExecFwk: std::shared_ptr dataMsg = event->GetSharedObject(); cJSON *innerMsg = cJSON_GetArrayItem(dataMsg.get(), 0); if (!IsString(innerMsg, PRIVACY_SUBTYPE)) { - DHLOGE("PRIVACY_SUBTYPE is invalid"); + DHLOGE("PRIVACY_SUBTYPE is invalid!"); return; } std::string subtype = cJSON_GetObjectItem(innerMsg, PRIVACY_SUBTYPE.c_str())->valuestring; if (!IsString(innerMsg, PRIVACY_NETWORKID)) { - DHLOGE("PRIVACY_NETWORKID is invalid"); + DHLOGE("PRIVACY_NETWORKID is invalid!"); return; } std::string networkId = cJSON_GetObjectItem(innerMsg, PRIVACY_NETWORKID.c_str())->valuestring; @@ -303,7 +319,7 @@ void ComponentPrivacy::ComponentEventHandler::ProcessStopPage(const AppExecFwk:: std::shared_ptr dataMsg = event->GetSharedObject(); cJSON *innerMsg = cJSON_GetArrayItem(dataMsg.get(), 0); if (!IsString(innerMsg, PRIVACY_SUBTYPE)) { - DHLOGE("PRIVACY_SUBTYPE is invalid"); + DHLOGE("PRIVACY_SUBTYPE is invalid!"); return; } std::string subtype = cJSON_GetObjectItem(innerMsg, PRIVACY_SUBTYPE.c_str())->valuestring; diff --git a/services/distributedhardwarefwkservice/src/componentmanager/dh_data_sync_trigger_listener.cpp b/services/distributedhardwarefwkservice/src/componentmanager/dh_data_sync_trigger_listener.cpp index 74ebc3ed..35d4cd1f 100644 --- a/services/distributedhardwarefwkservice/src/componentmanager/dh_data_sync_trigger_listener.cpp +++ b/services/distributedhardwarefwkservice/src/componentmanager/dh_data_sync_trigger_listener.cpp @@ -39,6 +39,10 @@ DHDataSyncTriggerListener::~DHDataSyncTriggerListener() void DHDataSyncTriggerListener::OnDataSyncTrigger(const std::string &networkId) { + if (networkId.empty() || networkId.length() > MAX_ID_LEN){ + DHLOGE("Network ID is invalid!"); + return; + } DHLOGI("Receive data sync trigger, networkId: %{public}s", GetAnonyString(networkId).c_str()); if (networkId.empty()) { DHLOGE("OnDataSyncTrigger networkId is empty"); diff --git a/services/distributedhardwarefwkservice/src/componentmanager/dh_state_listener.cpp b/services/distributedhardwarefwkservice/src/componentmanager/dh_state_listener.cpp index 9ce4d817..d99c39f3 100644 --- a/services/distributedhardwarefwkservice/src/componentmanager/dh_state_listener.cpp +++ b/services/distributedhardwarefwkservice/src/componentmanager/dh_state_listener.cpp @@ -38,6 +38,14 @@ DHStateListener::~DHStateListener() void DHStateListener::OnStateChanged(const std::string &networkId, const std::string &dhId, const BusinessState state) { + if (networkId.empty() || networkId.length() > MAX_ID_LEN){ + DHLOGE("Network ID is invalid!"); + return; + } + if (dhId.empty() || dhId.length() > MAX_ID_LEN){ + DHLOGE("DHID is invalide!"); + return; + } DHLOGI("Receive business state change, networkId: %{public}s, dhId: %{public}s, state: %{public}" PRIu32, GetAnonyString(networkId).c_str(), GetAnonyString(dhId).c_str(), (uint32_t)state); ComponentManager::GetInstance().UpdateBusinessState(networkId, dhId, state); diff --git a/services/distributedhardwarefwkservice/src/distributed_hardware_manager.cpp b/services/distributedhardwarefwkservice/src/distributed_hardware_manager.cpp index 2df70d68..227b51dc 100644 --- a/services/distributedhardwarefwkservice/src/distributed_hardware_manager.cpp +++ b/services/distributedhardwarefwkservice/src/distributed_hardware_manager.cpp @@ -97,6 +97,18 @@ int32_t DistributedHardwareManager::Release() int32_t DistributedHardwareManager::SendOnLineEvent(const std::string &networkId, const std::string &uuid, const std::string &udid, uint16_t deviceType) { + if (networkId.empty() || networkId.length() > MAX_ID_LEN){ + DHLOGE("Network ID is invalid!"); + return ERR_DH_FWK_PARA_INVALID; + } + if ( uuid.empty() || uuid.length() > MAX_ID_LEN ){ + DHLOGE("UUID is invalid!"); + return ERR_DH_FWK_PARA_INVALID; + } + if ( udid.empty() || udid.length() > MAX_ID_LEN ){ + DHLOGE("UDID is invalid!"); + return ERR_DH_FWK_PARA_INVALID; + } (void)deviceType; DHLOGI("SendOnLineEvent networkId = %{public}s, uuid = %{public}s, udid = %{public}s", GetAnonyString(networkId).c_str(), GetAnonyString(uuid).c_str(), GetAnonyString(udid).c_str()); @@ -116,6 +128,18 @@ int32_t DistributedHardwareManager::SendOnLineEvent(const std::string &networkId int32_t DistributedHardwareManager::SendOffLineEvent(const std::string &networkId, const std::string &uuid, const std::string &udid, uint16_t deviceType) { + if (networkId.empty() || networkId.length() > MAX_ID_LEN){ + DHLOGE("Network ID is invalid!"); + return ERR_DH_FWK_PARA_INVALID; + } + if ( uuid.empty() || uuid.length() > MAX_ID_LEN ){ + DHLOGE("UUID is invalid!"); + return ERR_DH_FWK_PARA_INVALID; + } + if ( udid.empty() || udid.length() > MAX_ID_LEN ){ + DHLOGE("UDID is invalid!"); + return ERR_DH_FWK_PARA_INVALID; + } (void)deviceType; DHLOGI("SendOffLineEvent networkId = %{public}s, uuid = %{public}s, udid = %{public}s", GetAnonyString(networkId).c_str(), GetAnonyString(uuid).c_str(), GetAnonyString(udid).c_str()); diff --git a/services/distributedhardwarefwkservice/src/distributed_hardware_manager_factory.cpp b/services/distributedhardwarefwkservice/src/distributed_hardware_manager_factory.cpp index 6133e6f7..097d6ae6 100644 --- a/services/distributedhardwarefwkservice/src/distributed_hardware_manager_factory.cpp +++ b/services/distributedhardwarefwkservice/src/distributed_hardware_manager_factory.cpp @@ -148,6 +148,18 @@ bool DistributedHardwareManagerFactory::IsInit() int32_t DistributedHardwareManagerFactory::SendOnLineEvent(const std::string &networkId, const std::string &uuid, const std::string &udid, uint16_t deviceType) { + if (networkId.empty() || networkId.length() > MAX_ID_LEN){ + DHLOGE("Network ID is invalid!"); + return ERR_DH_FWK_PARA_INVALID; + } + if ( uuid.empty() || uuid.length() > MAX_ID_LEN ){ + DHLOGE("UUID is invalid!"); + return ERR_DH_FWK_PARA_INVALID; + } + if ( udid.empty() || udid.length() > MAX_ID_LEN ){ + DHLOGE("UDID is invalid!"); + return ERR_DH_FWK_PARA_INVALID; + } int32_t ret = pthread_setname_np(pthread_self(), SEND_ONLINE); if (ret != DH_FWK_SUCCESS) { DHLOGE("SendOnLineEvent setname failed."); @@ -176,6 +188,18 @@ int32_t DistributedHardwareManagerFactory::SendOnLineEvent(const std::string &ne int32_t DistributedHardwareManagerFactory::SendOffLineEvent(const std::string &networkId, const std::string &uuid, const std::string &udid, uint16_t deviceType) { + if (networkId.empty() || networkId.length() > MAX_ID_LEN){ + DHLOGE("Network ID is invalid!"); + return ERR_DH_FWK_PARA_INVALID; + } + if ( uuid.empty() || uuid.length() > MAX_ID_LEN ){ + DHLOGE("UUID is invalid!"); + return ERR_DH_FWK_PARA_INVALID; + } + if ( udid.empty() || udid.length() > MAX_ID_LEN ){ + DHLOGE("UDID is invalid!"); + return ERR_DH_FWK_PARA_INVALID; + } if (!isInit && !Init()) { DHLOGE("distributedHardwareMgr is null"); return ERR_DH_FWK_HARDWARE_MANAGER_INIT_FAILED; @@ -191,6 +215,13 @@ int32_t DistributedHardwareManagerFactory::SendOffLineEvent(const std::string &n if (offlineResult != DH_FWK_SUCCESS) { DHLOGE("offline failed, errCode = %{public}d", offlineResult); } + + DHContext::GetInstance().RemoveOnlineDeviceByUUID(uuid); + if (DistributedHardwareManager::GetInstance().GetOnLineCount() == 0 && + DHContext::GetInstance().GetIsomerismConnectCount() == 0) { + DHLOGI("all devices are offline, start to free the resource"); + UnInit(); + } return DH_FWK_SUCCESS; } diff --git a/services/distributedhardwarefwkservice/src/distributed_hardware_service.cpp b/services/distributedhardwarefwkservice/src/distributed_hardware_service.cpp index 3f2bf503..e21938a7 100644 --- a/services/distributedhardwarefwkservice/src/distributed_hardware_service.cpp +++ b/services/distributedhardwarefwkservice/src/distributed_hardware_service.cpp @@ -306,6 +306,10 @@ int DistributedHardwareService::Dump(int32_t fd, const std::vector MAX_ID_LEN){ + DHLOGE("Network ID is invalid!"); + return ERR_DH_FWK_PARA_INVALID; + } std::map sinkMap = ComponentManager::GetInstance().GetDHSinkInstance(); if (sinkMap.find(dhType) == sinkMap.end()) { DHLOGE("PauseDistributedHardware for DHType: %{public}u not init sink handler", (uint32_t)dhType); @@ -321,6 +325,10 @@ int32_t DistributedHardwareService::PauseDistributedHardware(DHType dhType, cons int32_t DistributedHardwareService::ResumeDistributedHardware(DHType dhType, const std::string &networkId) { + if (networkId.empty() || networkId.length() > MAX_ID_LEN){ + DHLOGE("Network ID is invalid!"); + return ERR_DH_FWK_PARA_INVALID; + } std::map sinkMap = ComponentManager::GetInstance().GetDHSinkInstance(); if (sinkMap.find(dhType) == sinkMap.end()) { DHLOGE("ResumeDistributedHardware for DHType: %{public}u not init sink handler", (uint32_t)dhType); @@ -336,6 +344,10 @@ int32_t DistributedHardwareService::ResumeDistributedHardware(DHType dhType, con int32_t DistributedHardwareService::StopDistributedHardware(DHType dhType, const std::string &networkId) { + if (networkId.empty() || networkId.length() > MAX_ID_LEN){ + DHLOGE("Network ID is invalid!"); + return ERR_DH_FWK_PARA_INVALID; + } std::map sinkMap = ComponentManager::GetInstance().GetDHSinkInstance(); if (sinkMap.find(dhType) == sinkMap.end()) { DHLOGE("StopDistributedHardware for DHType: %{public}u not init sink handler", (uint32_t)dhType); diff --git a/services/distributedhardwarefwkservice/src/distributed_hardware_stub.cpp b/services/distributedhardwarefwkservice/src/distributed_hardware_stub.cpp index dbe3565f..dc79dde6 100644 --- a/services/distributedhardwarefwkservice/src/distributed_hardware_stub.cpp +++ b/services/distributedhardwarefwkservice/src/distributed_hardware_stub.cpp @@ -25,7 +25,6 @@ #include "distributed_hardware_log.h" #include "ipc_skeleton.h" #include "publisher_listener_proxy.h" -#include "tokenid_kit.h" namespace OHOS { namespace DistributedHardware { @@ -310,11 +309,6 @@ int32_t DistributedHardwareStub::StopDistributedHardwareInner(MessageParcel &dat bool DistributedHardwareStub::HasAccessDHPermission() { - uint64_t fullTokenId = IPCSkeleton::GetCallingFullTokenID(); - if (!OHOS::Security::AccessToken::TokenIdKit::IsSystemAppByFullTokenID(fullTokenId)) { - DHLOGE("GetCallerProcessName not system hap."); - return false; - } Security::AccessToken::AccessTokenID callerToken = IPCSkeleton::GetCallingTokenID(); const std::string permissionName = "ohos.permission.ACCESS_DISTRIBUTED_HARDWARE"; int32_t result = Security::AccessToken::AccessTokenKit::VerifyAccessToken(callerToken, diff --git a/services/distributedhardwarefwkservice/src/hidumphelper/enabled_comps_dump.cpp b/services/distributedhardwarefwkservice/src/hidumphelper/enabled_comps_dump.cpp index abfd99cb..62989f69 100644 --- a/services/distributedhardwarefwkservice/src/hidumphelper/enabled_comps_dump.cpp +++ b/services/distributedhardwarefwkservice/src/hidumphelper/enabled_comps_dump.cpp @@ -15,12 +15,24 @@ #include "enabled_comps_dump.h" +#include "constants.h" +#include "distributed_hardware_log.h" +#include "distributed_hardware_errno.h" + namespace OHOS { namespace DistributedHardware { IMPLEMENT_SINGLE_INSTANCE(EnabledCompsDump); void EnabledCompsDump::DumpEnabledComp(const std::string &networkId, const DHType dhType, const std::string &dhId) { + if (networkId.empty() || networkId.length() > MAX_ID_LEN){ + DHLOGE("Network ID is invalid!"); + return; + } + if (dhId.empty() || dhId.length() > MAX_ID_LEN){ + DHLOGE("DHID is invalide!"); + return; + } HidumpCompInfo info(networkId, dhType, dhId); std::lock_guard lock(compInfosMutex_); @@ -29,6 +41,14 @@ void EnabledCompsDump::DumpEnabledComp(const std::string &networkId, const DHTyp void EnabledCompsDump::DumpDisabledComp(const std::string &networkId, const DHType dhType, const std::string &dhId) { + if (networkId.empty() || networkId.length() > MAX_ID_LEN){ + DHLOGE("Network ID is invalid!"); + return; + } + if (dhId.empty() || dhId.length() > MAX_ID_LEN){ + DHLOGE("DHID is invalide!"); + return; + } HidumpCompInfo info(networkId, dhType, dhId); std::lock_guard lock(compInfosMutex_); diff --git a/services/distributedhardwarefwkservice/src/ipc/publisher_listener_proxy.cpp b/services/distributedhardwarefwkservice/src/ipc/publisher_listener_proxy.cpp index 11fdf70a..c63b8bf6 100644 --- a/services/distributedhardwarefwkservice/src/ipc/publisher_listener_proxy.cpp +++ b/services/distributedhardwarefwkservice/src/ipc/publisher_listener_proxy.cpp @@ -40,7 +40,7 @@ void PublisherListenerProxy::OnMessage(const DHTopic topic, const std::string& m return; } if (message.size() == 0 || message.size() > MAX_MESSAGE_LEN) { - DHLOGE("Message is invalid"); + DHLOGE("Message is invalid!"); return; } diff --git a/services/distributedhardwarefwkservice/src/localhardwaremanager/local_hardware_manager.cpp b/services/distributedhardwarefwkservice/src/localhardwaremanager/local_hardware_manager.cpp index 1146c1d9..05386889 100644 --- a/services/distributedhardwarefwkservice/src/localhardwaremanager/local_hardware_manager.cpp +++ b/services/distributedhardwarefwkservice/src/localhardwaremanager/local_hardware_manager.cpp @@ -197,7 +197,7 @@ void LocalHardwareManager::GetLocalCapabilityMapByPrefix(const DHType dhType, Ca { std::string localDeviceId = DHContext::GetInstance().GetDeviceInfo().deviceId; if (localDeviceId.size() == 0 || localDeviceId.size() > MAX_ID_LEN) { - DHLOGE("LocalDeviceId is invalid"); + DHLOGE("LocalDeviceId is invalid!"); return; } if (DHTypePrefixMap.find(dhType) == DHTypePrefixMap.end()) { diff --git a/services/distributedhardwarefwkservice/src/lowlatency/low_latency_listener.cpp b/services/distributedhardwarefwkservice/src/lowlatency/low_latency_listener.cpp index 3cd6c701..d2303926 100644 --- a/services/distributedhardwarefwkservice/src/lowlatency/low_latency_listener.cpp +++ b/services/distributedhardwarefwkservice/src/lowlatency/low_latency_listener.cpp @@ -46,7 +46,7 @@ void LowLatencyListener::OnMessage(const DHTopic topic, const std::string& messa return; } if (message.size() == 0 || message.size() > MAX_MESSAGE_LEN) { - DHLOGE("Message is invalid"); + DHLOGE("Message is invalid!"); return; } cJSON *jsonObj = cJSON_Parse(message.c_str()); @@ -55,12 +55,12 @@ void LowLatencyListener::OnMessage(const DHTopic topic, const std::string& messa return; } if (!IsUInt32(jsonObj, DH_TYPE)) { - DHLOGE("The DH_TYPE key is invalid"); + DHLOGE("The DH_TYPE key is invalid!"); cJSON_Delete(jsonObj); return; } if (!IsBool(jsonObj, LOW_LATENCY_ENABLE)) { - DHLOGE("The LOW_LATENCY_ENABLE key is invalid"); + DHLOGE("The LOW_LATENCY_ENABLE key is invalid!"); cJSON_Delete(jsonObj); return; } diff --git a/services/distributedhardwarefwkservice/src/publisher/publisher_item.cpp b/services/distributedhardwarefwkservice/src/publisher/publisher_item.cpp index fd757809..09a77bf0 100644 --- a/services/distributedhardwarefwkservice/src/publisher/publisher_item.cpp +++ b/services/distributedhardwarefwkservice/src/publisher/publisher_item.cpp @@ -65,7 +65,7 @@ void PublisherItem::RemoveListener(const sptr &listener) void PublisherItem::PublishMessage(const std::string &message) { if (message.size() == 0 || message.size() > MAX_MESSAGE_LEN) { - DHLOGE("Message is invalid"); + DHLOGE("Message is invalid!"); return; } std::lock_guard lock(mutex_); diff --git a/services/distributedhardwarefwkservice/src/resourcemanager/capability_info.cpp b/services/distributedhardwarefwkservice/src/resourcemanager/capability_info.cpp index 7f65f5f8..c9c30911 100644 --- a/services/distributedhardwarefwkservice/src/resourcemanager/capability_info.cpp +++ b/services/distributedhardwarefwkservice/src/resourcemanager/capability_info.cpp @@ -47,6 +47,10 @@ std::string CapabilityInfo::GetDeviceId() const void CapabilityInfo::SetDeviceId(const std::string &deviceId) { + if (deviceId.empty() || deviceId.length() > MAX_ID_LEN){ + DHLOGE("Device ID is invalid!"); + return; + } this->deviceId_ = deviceId; } @@ -120,6 +124,10 @@ std::string CapabilityInfo::GetAnonymousKey() const int32_t CapabilityInfo::FromJsonString(const std::string &jsonStr) { + if (jsonStr.empty() || jsonStr.length() > MAX_JSON_SIZE){ + DHLOGE("Json string is invalid!"); + return ERR_DH_FWK_PARA_INVALID; + } cJSON *jsonObj = cJSON_Parse(jsonStr.c_str()); if (jsonObj == NULL) { DHLOGE("jsonStr parse failed"); @@ -185,6 +193,10 @@ bool CapabilityInfo::Compare(const CapabilityInfo& capInfo) void ToJson(cJSON *jsonObject, const CapabilityInfo &capability) { + if (jsonObject == nullptr) { + DHLOGE("Json pointer is nullptr!"); + return; + } cJSON_AddStringToObject(jsonObject, DH_ID.c_str(), capability.GetDHId().c_str()); cJSON_AddStringToObject(jsonObject, DEV_ID.c_str(), capability.GetDeviceId().c_str()); cJSON_AddStringToObject(jsonObject, DEV_NAME.c_str(), capability.GetDeviceName().c_str()); @@ -196,6 +208,10 @@ void ToJson(cJSON *jsonObject, const CapabilityInfo &capability) void FromJson(const cJSON *jsonObject, CapabilityInfo &capability) { + if (jsonObject == nullptr) { + DHLOGE("Json pointer is nullptr!"); + return; + } if (!IsString(jsonObject, DH_ID)) { DHLOGE("DH_ID is invalid!"); return; diff --git a/services/distributedhardwarefwkservice/src/resourcemanager/capability_info_manager.cpp b/services/distributedhardwarefwkservice/src/resourcemanager/capability_info_manager.cpp index 7c4eed6f..efa0716f 100644 --- a/services/distributedhardwarefwkservice/src/resourcemanager/capability_info_manager.cpp +++ b/services/distributedhardwarefwkservice/src/resourcemanager/capability_info_manager.cpp @@ -119,6 +119,10 @@ int32_t CapabilityInfoManager::UnInit() int32_t CapabilityInfoManager::SyncDeviceInfoFromDB(const std::string &deviceId) { + if (deviceId.empty() || deviceId.length() > MAX_ID_LEN){ + DHLOGE("Device ID is invalid!"); + return ERR_DH_FWK_PARA_INVALID; + } DHLOGI("Sync DeviceInfo from DB, deviceId: %{public}s", GetAnonyString(deviceId).c_str()); std::lock_guard lock(capInfoMgrMutex_); if (dbAdapterPtr_ == nullptr) { @@ -185,7 +189,7 @@ int32_t CapabilityInfoManager::SyncRemoteCapabilityInfos() int32_t CapabilityInfoManager::AddCapability(const std::vector> &resInfos) { - if (resInfos.size() == 0 || resInfos.size() > MAX_DB_RECORD_SIZE) { + if (resInfos.empty() || resInfos.size() > MAX_DB_RECORD_SIZE) { DHLOGE("ResInfos size is invalid!"); return ERR_DH_FWK_RESOURCE_RES_DB_DATA_INVALID; } @@ -226,6 +230,10 @@ int32_t CapabilityInfoManager::AddCapability(const std::vector> &resInfos) { + if (resInfos.empty() || resInfos.size() > MAX_DB_RECORD_SIZE) { + DHLOGE("ResInfos size is invalid!"); + return ERR_DH_FWK_RESOURCE_RES_DB_DATA_INVALID; + } std::lock_guard lock(capInfoMgrMutex_); for (auto &resInfo : resInfos) { if (resInfo == nullptr) { @@ -240,6 +248,10 @@ int32_t CapabilityInfoManager::AddCapabilityInMem(const std::vector MAX_ID_LEN){ + DHLOGE("Device ID is invalid!"); + return ERR_DH_FWK_PARA_INVALID; + } if (deviceId.size() == 0 || deviceId.size() > MAX_ID_LEN) { DHLOGE("DeviceId is invalid!"); return ERR_DH_FWK_PARA_INVALID; @@ -269,6 +281,10 @@ int32_t CapabilityInfoManager::RemoveCapabilityInfoInDB(const std::string &devic int32_t CapabilityInfoManager::RemoveCapabilityInfoByKey(const std::string &key) { + if ( key.empty() || key.length() > MAX_ID_LEN ){ + DHLOGE("Key is invalid!"); + return ERR_DH_FWK_PARA_INVALID; + } DHLOGI("Remove capability device info, key: %{public}s", GetAnonyString(key).c_str()); std::lock_guard lock(capInfoMgrMutex_); if (dbAdapterPtr_ == nullptr) { @@ -288,6 +304,10 @@ int32_t CapabilityInfoManager::RemoveCapabilityInfoByKey(const std::string &key) int32_t CapabilityInfoManager::RemoveCapabilityInfoInMem(const std::string &deviceId) { + if (deviceId.empty() || deviceId.length() > MAX_ID_LEN){ + DHLOGE("Device ID is invalid!"); + return ERR_DH_FWK_PARA_INVALID; + } DHLOGI("remove capability device info in memory, deviceId: %{public}s", GetAnonyString(deviceId).c_str()); std::lock_guard lock(capInfoMgrMutex_); for (auto iter = globalCapInfoMap_.begin(); iter != globalCapInfoMap_.end();) { @@ -369,6 +389,10 @@ void CapabilityInfoManager::OnChange(const DistributedKv::DataOrigin &origin, Ke void CapabilityInfoManager::HandleCapabilityAddChange(const std::vector &insertRecords) { + if (insertRecords.empty() || insertRecords.size() > MAX_DB_RECORD_SIZE){ + DHLOGE("Records vector is invalide!"); + return; + } std::lock_guard lock(capInfoMgrMutex_); for (const auto &item : insertRecords) { const std::string value = item.value.ToString(); @@ -403,6 +427,10 @@ void CapabilityInfoManager::HandleCapabilityAddChange(const std::vector &updateRecords) { + if (updateRecords.empty() || updateRecords.size() > MAX_DB_RECORD_SIZE){ + DHLOGE("Records vector is invalide!"); + return; + } std::lock_guard lock(capInfoMgrMutex_); for (const auto &item : updateRecords) { const std::string value = item.value.ToString(); @@ -419,6 +447,10 @@ void CapabilityInfoManager::HandleCapabilityUpdateChange(const std::vector &deleteRecords) { + if (deleteRecords.empty() || deleteRecords.size() > MAX_DB_RECORD_SIZE){ + DHLOGE("Records vector is invalide!"); + return; + } std::lock_guard lock(capInfoMgrMutex_); for (const auto &item : deleteRecords) { const std::string value = item.value.ToString(); @@ -458,6 +490,10 @@ bool CapabilityInfoManager::IsCapabilityMatchFilter(const std::shared_ptr MAX_MESSAGE_LEN){ + DHLOGE("Value is invalid!"); + return false; + } bool isMatch = false; switch (filter) { @@ -498,6 +534,14 @@ bool CapabilityInfoManager::IsCapabilityMatchFilter(const std::shared_ptr> &resInfos) { + if (deviceId.empty() || deviceId.length() > MAX_ID_LEN){ + DHLOGE("Device ID is invalid!"); + return; + } + if (resInfos.size() == 0 || resInfos.size() > MAX_DB_RECORD_SIZE) { + DHLOGE("ResInfos size is invalid!"); + return; + } std::lock_guard lock(capInfoMgrMutex_); for (auto &capabilityInfo : globalCapInfoMap_) { if (IsCapKeyMatchDeviceId(capabilityInfo.first, deviceId)) { @@ -508,6 +552,14 @@ void CapabilityInfoManager::GetCapabilitiesByDeviceId(const std::string &deviceI bool CapabilityInfoManager::HasCapability(const std::string &deviceId, const std::string &dhId) { + if (dhId.empty() || dhId.length() > MAX_ID_LEN){ + DHLOGE("DHID is invalide!"); + return false; + } + if (deviceId.empty() || deviceId.length() > MAX_ID_LEN){ + DHLOGE("Device ID is invalid!"); + return false; + } std::lock_guard lock(capInfoMgrMutex_); std::string kvKey = GetCapabilityKey(deviceId, dhId); if (globalCapInfoMap_.find(kvKey) == globalCapInfoMap_.end()) { @@ -519,6 +571,14 @@ bool CapabilityInfoManager::HasCapability(const std::string &deviceId, const std int32_t CapabilityInfoManager::GetCapability(const std::string &deviceId, const std::string &dhId, std::shared_ptr &capPtr) { + if (dhId.empty() || dhId.length() > MAX_ID_LEN){ + DHLOGE("DHID is invalide!"); + return ERR_DH_FWK_PARA_INVALID; + } + if (deviceId.empty() || deviceId.length() > MAX_ID_LEN){ + DHLOGE("Device ID is invalid!"); + return ERR_DH_FWK_PARA_INVALID; + } std::lock_guard lock(capInfoMgrMutex_); std::string key = GetCapabilityKey(deviceId, dhId); if (globalCapInfoMap_.find(key) == globalCapInfoMap_.end()) { @@ -531,6 +591,10 @@ int32_t CapabilityInfoManager::GetCapability(const std::string &deviceId, const int32_t CapabilityInfoManager::GetDataByKey(const std::string &key, std::shared_ptr &capInfoPtr) { + if ( key.empty() || key.length() > MAX_ID_LEN ){ + DHLOGE("Key is invalid!"); + return ERR_DH_FWK_PARA_INVALID; + } std::lock_guard lock(capInfoMgrMutex_); if (dbAdapterPtr_ == nullptr) { DHLOGI("dbAdapterPtr_ is null"); @@ -558,6 +622,10 @@ int32_t CapabilityInfoManager::GetDataByDHType(const DHType dhType, CapabilityIn int32_t CapabilityInfoManager::GetDataByKeyPrefix(const std::string &keyPrefix, CapabilityInfoMap &capabilityMap) { + if ( keyPrefix.empty() || keyPrefix.length() > MAX_ID_LEN ){ + DHLOGE("Key prefix is invalid!"); + return ERR_DH_FWK_PARA_INVALID; + } std::lock_guard lock(capInfoMgrMutex_); if (dbAdapterPtr_ == nullptr) { DHLOGE("dbAdapterPtr is null"); @@ -593,6 +661,10 @@ void CapabilityInfoManager::DumpCapabilityInfos(std::vector &cap std::vector CapabilityInfoManager::GetEntriesByKeys(const std::vector &keys) { + if (keys.empty() || keys.size() > MAX_ARR_SIZE){ + DHLOGE("Length of vactor of keys is invalid!"); + return {}; + } DHLOGI("call"); if (keys.empty()) { DHLOGE("keys empty."); diff --git a/services/distributedhardwarefwkservice/src/resourcemanager/capability_utils.cpp b/services/distributedhardwarefwkservice/src/resourcemanager/capability_utils.cpp index 52d1c811..274841d3 100644 --- a/services/distributedhardwarefwkservice/src/resourcemanager/capability_utils.cpp +++ b/services/distributedhardwarefwkservice/src/resourcemanager/capability_utils.cpp @@ -31,6 +31,10 @@ std::string GetCapabilityKey(const std::string &deviceId, const std::string &dhI bool IsCapKeyMatchDeviceId(const std::string &key, const std::string &deviceId) { + if (deviceId.empty() || deviceId.length() > MAX_ID_LEN){ + DHLOGE("Device ID is invalid!"); + return false; + } std::size_t separatorPos = key.find(RESOURCE_SEPARATOR); if (separatorPos == std::string::npos) { return false; diff --git a/services/distributedhardwarefwkservice/src/resourcemanager/db_adapter.cpp b/services/distributedhardwarefwkservice/src/resourcemanager/db_adapter.cpp index cadc081b..b5e6bc93 100644 --- a/services/distributedhardwarefwkservice/src/resourcemanager/db_adapter.cpp +++ b/services/distributedhardwarefwkservice/src/resourcemanager/db_adapter.cpp @@ -190,6 +190,10 @@ int32_t DBAdapter::ReInit(bool isAutoSync) std::string DBAdapter::GetNetworkIdByKey(const std::string &key) { + if ( key.empty() || key.length() > MAX_ID_LEN ){ + DHLOGE("Key is invalid!"); + return ""; + } DHLOGI("Get networkId by key: %{public}s", GetAnonyString(key).c_str()); std::string deviceId = DHContext::GetInstance().GetDeviceIdByDBGetPrefix(key); if (deviceId.empty()) { @@ -217,6 +221,10 @@ std::string DBAdapter::GetNetworkIdByKey(const std::string &key) void DBAdapter::SyncByNotFound(const std::string &key) { + if ( key.empty() || key.length() > MAX_ID_LEN ){ + DHLOGE("Key is invalid!"); + return; + } std::string networkId = GetNetworkIdByKey(key); if (networkId.empty()) { DHLOGW("The networkId emtpy."); @@ -232,6 +240,14 @@ void DBAdapter::SyncByNotFound(const std::string &key) int32_t DBAdapter::GetDataByKey(const std::string &key, std::string &data) { + if ( key.empty() || key.length() > MAX_ID_LEN ){ + DHLOGE("Key is invalid!"); + return ERR_DH_FWK_PARA_INVALID; + } + if ( data.empty() || data.length() > MAX_MESSAGE_LEN ){ + DHLOGE("Key is invalid!"); + return ERR_DH_FWK_PARA_INVALID; + } DHLOGI("Get data by key: %{public}s, storeId: %{public}s, dataType: %{public}d", GetAnonyString(key).c_str(), storeId_.storeId.c_str(), static_cast(this->dataType)); std::lock_guard lock(dbAdapterMutex_); @@ -262,6 +278,10 @@ int32_t DBAdapter::GetDataByKey(const std::string &key, std::string &data) int32_t DBAdapter::GetDataByKeyPrefix(const std::string &keyPrefix, std::vector &values) { + if ( keyPrefix.empty() || keyPrefix.length() > MAX_ID_LEN ){ + DHLOGE("Keyprefix is invalid!"); + return ERR_DH_FWK_PARA_INVALID; + } DHLOGI("Get data by key prefix: %{public}s, storeId: %{public}s, dataType: %{public}d", GetAnonyString(keyPrefix).c_str(), storeId_.storeId.c_str(), static_cast(this->dataType)); std::lock_guard lock(dbAdapterMutex_); @@ -300,8 +320,12 @@ int32_t DBAdapter::GetDataByKeyPrefix(const std::string &keyPrefix, std::vector< int32_t DBAdapter::PutData(const std::string &key, const std::string &value) { - if (key.empty() || key.size() > MAX_MESSAGE_LEN || value.empty() || value.size() > MAX_MESSAGE_LEN) { - DHLOGI("Param is invalid!"); + if ( key.empty() || key.length() > MAX_ID_LEN ){ + DHLOGE("Key is invalid!"); + return ERR_DH_FWK_PARA_INVALID; + } + if (value.empty() || value.length() > MAX_MESSAGE_LEN){ + DHLOGE("Value is invalid!"); return ERR_DH_FWK_PARA_INVALID; } std::lock_guard lock(dbAdapterMutex_); @@ -321,6 +345,14 @@ int32_t DBAdapter::PutData(const std::string &key, const std::string &value) int32_t DBAdapter::PutDataBatch(const std::vector &keys, const std::vector &values) { + if (keys.empty() || keys.size() > MAX_ARR_SIZE){ + DHLOGE("Length of vactor of keys is invalid!"); + return ERR_DH_FWK_PARA_INVALID; + } + if ( values.empty() || values.size() > MAX_ARR_SIZE ){ + DHLOGE("Length of array of value is invalid!"); + return ERR_DH_FWK_PARA_INVALID; + } std::lock_guard lock(dbAdapterMutex_); if (kvStoragePtr_ == nullptr) { DHLOGE("kvStoragePtr_ is null"); @@ -471,6 +503,10 @@ void DBAdapter::DeleteKvStore() int32_t DBAdapter::RemoveDeviceData(const std::string &deviceId) { + if (deviceId.empty() || deviceId.length() > MAX_ID_LEN){ + DHLOGE("Device ID is invalid!"); + return ERR_DH_FWK_PARA_INVALID; + } std::lock_guard lock(dbAdapterMutex_); if (kvStoragePtr_ == nullptr) { DHLOGE("kvStoragePtr_ is null"); @@ -487,6 +523,10 @@ int32_t DBAdapter::RemoveDeviceData(const std::string &deviceId) int32_t DBAdapter::RemoveDataByKey(const std::string &key) { + if ( key.length() <= 0 || key.length() > MAX_ID_LEN){ + DHLOGE("Key is invalide!"); + return ERR_DH_FWK_PARA_INVALID; + } std::lock_guard lock(dbAdapterMutex_); if (kvStoragePtr_ == nullptr) { DHLOGE("kvStoragePtr_ is null"); @@ -504,6 +544,10 @@ int32_t DBAdapter::RemoveDataByKey(const std::string &key) std::vector DBAdapter::GetEntriesByKeys(const std::vector &keys) { + if (keys.empty() || keys.size() > MAX_ARR_SIZE){ + DHLOGE("Length of vactor of keys is invalid!"); + return {}; + } DHLOGI("call"); std::vector entries; if (keys.empty()) { diff --git a/services/distributedhardwarefwkservice/src/resourcemanager/local_capability_info_manager.cpp b/services/distributedhardwarefwkservice/src/resourcemanager/local_capability_info_manager.cpp index 574e9842..33573ea6 100644 --- a/services/distributedhardwarefwkservice/src/resourcemanager/local_capability_info_manager.cpp +++ b/services/distributedhardwarefwkservice/src/resourcemanager/local_capability_info_manager.cpp @@ -83,6 +83,10 @@ int32_t LocalCapabilityInfoManager::UnInit() int32_t LocalCapabilityInfoManager::SyncDeviceInfoFromDB(const std::string &deviceId) { + if (deviceId.empty() || deviceId.length() > MAX_ID_LEN){ + DHLOGE("Device ID is invalid!"); + return ERR_DH_FWK_PARA_INVALID; + } DHLOGI("Sync DeviceInfo from DB, deviceId: %{public}s", GetAnonyString(deviceId).c_str()); std::lock_guard lock(capInfoMgrMutex_); if (dbAdapterPtr_ == nullptr) { @@ -111,7 +115,7 @@ int32_t LocalCapabilityInfoManager::SyncDeviceInfoFromDB(const std::string &devi int32_t LocalCapabilityInfoManager::AddCapability(const std::vector> &resInfos) { - if (resInfos.size() == 0 || resInfos.size() > MAX_DB_RECORD_SIZE) { + if (resInfos.empty() || resInfos.size() > MAX_DB_RECORD_SIZE) { DHLOGE("ResInfos size is invalid!"); return ERR_DH_FWK_RESOURCE_RES_DB_DATA_INVALID; } @@ -146,6 +150,10 @@ int32_t LocalCapabilityInfoManager::AddCapability(const std::vector MAX_KEY_SIZE ){ + DHLOGE("Key is invalid!"); + return ERR_DH_FWK_PARA_INVALID; + } DHLOGI("Remove capability device info, key: %{public}s", GetAnonyString(key).c_str()); std::lock_guard lock(capInfoMgrMutex_); if (dbAdapterPtr_ == nullptr) { @@ -166,6 +174,14 @@ int32_t LocalCapabilityInfoManager::RemoveCapabilityInfoByKey(const std::string void LocalCapabilityInfoManager::GetCapabilitiesByDeviceId(const std::string &deviceId, std::vector> &resInfos) { + if (deviceId.empty() || deviceId.length() > MAX_ID_LEN){ + DHLOGE("Device ID is invalid!"); + return; + } + if (resInfos.size() == 0 || resInfos.size() > MAX_DB_RECORD_SIZE) { + DHLOGE("ResInfos size is invalid!"); + return; + } std::lock_guard lock(capInfoMgrMutex_); for (auto &capabilityInfo : globalCapInfoMap_) { if (IsCapKeyMatchDeviceId(capabilityInfo.first, deviceId)) { @@ -177,6 +193,14 @@ void LocalCapabilityInfoManager::GetCapabilitiesByDeviceId(const std::string &de int32_t LocalCapabilityInfoManager::GetCapability(const std::string &deviceId, const std::string &dhId, std::shared_ptr &capPtr) { + if (deviceId.empty() || deviceId.length() > MAX_ID_LEN){ + DHLOGE("Device ID is invalid!"); + return ERR_DH_FWK_PARA_INVALID; + } + if (dhId.empty() || dhId.length() > MAX_ID_LEN){ + DHLOGE("DHID is invalide!"); + return ERR_DH_FWK_PARA_INVALID; + } std::lock_guard lock(capInfoMgrMutex_); std::string key = GetCapabilityKey(deviceId, dhId); if (globalCapInfoMap_.find(key) == globalCapInfoMap_.end()) { @@ -189,6 +213,10 @@ int32_t LocalCapabilityInfoManager::GetCapability(const std::string &deviceId, c int32_t LocalCapabilityInfoManager::GetDataByKey(const std::string &key, std::shared_ptr &capInfoPtr) { + if ( key.empty() || key.length() > MAX_ID_LEN ){ + DHLOGE("Key is invalid!"); + return ERR_DH_FWK_PARA_INVALID; + } std::lock_guard lock(capInfoMgrMutex_); if (dbAdapterPtr_ == nullptr) { DHLOGI("dbAdapterPtr_ is null"); @@ -216,6 +244,10 @@ int32_t LocalCapabilityInfoManager::GetDataByDHType(const DHType dhType, Capabil int32_t LocalCapabilityInfoManager::GetDataByKeyPrefix(const std::string &keyPrefix, CapabilityInfoMap &capabilityMap) { + if ( keyPrefix.empty() || keyPrefix.length() > MAX_KEY_SIZE ){ + DHLOGE("Key prefix is invalid!"); + return ERR_DH_FWK_PARA_INVALID; + } std::lock_guard lock(capInfoMgrMutex_); if (dbAdapterPtr_ == nullptr) { DHLOGE("dbAdapterPtr is null"); diff --git a/services/distributedhardwarefwkservice/src/resourcemanager/meta_capability_info.cpp b/services/distributedhardwarefwkservice/src/resourcemanager/meta_capability_info.cpp index 6630e29c..4180f49a 100644 --- a/services/distributedhardwarefwkservice/src/resourcemanager/meta_capability_info.cpp +++ b/services/distributedhardwarefwkservice/src/resourcemanager/meta_capability_info.cpp @@ -52,6 +52,10 @@ void MetaCapabilityInfo::SetSinkVersion(const std::string &sinkVersion) int32_t MetaCapabilityInfo::FromJsonString(const std::string &jsonStr) { + if (jsonStr.empty() || jsonStr.length() > MAX_JSON_SIZE){ + DHLOGE("Json string is invalid!"); + return ERR_DH_FWK_PARA_INVALID; + } cJSON *jsonObj = cJSON_Parse(jsonStr.c_str()); if (jsonObj == NULL) { DHLOGE("jsonStr parse failed"); @@ -143,6 +147,10 @@ std::string MetaCapabilityInfo::GetAnonymousKey() const void ToJson(cJSON *jsonObject, const MetaCapabilityInfo &metaCapInfo) { + if (jsonObject == nullptr) { + DHLOGE("Json pointer is nullptr!"); + return; + } cJSON_AddStringToObject(jsonObject, DH_ID.c_str(), metaCapInfo.GetDHId().c_str()); cJSON_AddStringToObject(jsonObject, DEV_ID.c_str(), metaCapInfo.GetDeviceId().c_str()); cJSON_AddStringToObject(jsonObject, DEV_NAME.c_str(), metaCapInfo.GetDeviceName().c_str()); @@ -156,6 +164,10 @@ void ToJson(cJSON *jsonObject, const MetaCapabilityInfo &metaCapInfo) void FromJson(const cJSON *jsonObject, MetaCapabilityInfo &metaCapInfo) { + if (jsonObject == nullptr) { + DHLOGE("Json pointer is nullptr!"); + return; + } if (!IsString(jsonObject, DH_ID)) { DHLOGE("DH_ID is invalid!"); return; diff --git a/services/distributedhardwarefwkservice/src/resourcemanager/meta_info_manager.cpp b/services/distributedhardwarefwkservice/src/resourcemanager/meta_info_manager.cpp index 7eddc2ad..23f98513 100644 --- a/services/distributedhardwarefwkservice/src/resourcemanager/meta_info_manager.cpp +++ b/services/distributedhardwarefwkservice/src/resourcemanager/meta_info_manager.cpp @@ -156,6 +156,10 @@ int32_t MetaInfoManager::AddMetaCapInfos(const std::vector MAX_HASH_SIZE ){ + DHLOGE("UDID hash is invalid!"); + return ERR_DH_FWK_PARA_INVALID; + } DHLOGI("Sync MetaInfo from DB, udidHash: %{public}s", GetAnonyString(udidHash).c_str()); std::lock_guard lock(metaInfoMgrMutex_); if (dbAdapterPtr_ == nullptr) { @@ -224,6 +228,10 @@ int32_t MetaInfoManager::SyncRemoteMetaInfos() int32_t MetaInfoManager::GetDataByKeyPrefix(const std::string &keyPrefix, MetaCapInfoMap &metaCapMap) { + if ( keyPrefix.empty() || keyPrefix.length() > MAX_KEY_SIZE ){ + DHLOGE("Key orefix is invalid!"); + return ERR_DH_FWK_PARA_INVALID; + } std::lock_guard lock(metaInfoMgrMutex_); if (dbAdapterPtr_ == nullptr) { DHLOGE("dbAdapterPtr is null"); @@ -251,6 +259,10 @@ int32_t MetaInfoManager::GetDataByKeyPrefix(const std::string &keyPrefix, MetaCa int32_t MetaInfoManager::RemoveMetaInfoByKey(const std::string &key) { + if ( key.empty() || key.length() > MAX_KEY_SIZE ){ + DHLOGE("Key is invalid!"); + return ERR_DH_FWK_PARA_INVALID; + } DHLOGI("Remove device metaInfo, key: %{public}s", GetAnonyString(key).c_str()); std::lock_guard lock(metaInfoMgrMutex_); if (dbAdapterPtr_ == nullptr) { @@ -269,6 +281,14 @@ int32_t MetaInfoManager::RemoveMetaInfoByKey(const std::string &key) int32_t MetaInfoManager::GetMetaCapInfo(const std::string &udidHash, const std::string &dhId, std::shared_ptr &metaCapPtr) { + if ( udidHash.empty() || udidHash.length() > MAX_HASH_SIZE ){ + DHLOGE("UDID hash is invalid!"); + return ERR_DH_FWK_PARA_INVALID; + } + if (dhId.empty() || dhId.length() > MAX_ID_LEN){ + DHLOGE("DHID is invalide!"); + return ERR_DH_FWK_PARA_INVALID; + } std::lock_guard lock(metaInfoMgrMutex_); std::string key = GetCapabilityKey(udidHash, dhId); if (globalMetaInfoMap_.find(key) == globalMetaInfoMap_.end()) { @@ -282,6 +302,10 @@ int32_t MetaInfoManager::GetMetaCapInfo(const std::string &udidHash, void MetaInfoManager::GetMetaCapInfosByUdidHash(const std::string &udidHash, std::vector> &metaCapInfos) { + if ( udidHash.empty() || udidHash.length() > MAX_HASH_SIZE ){ + DHLOGE("UDID hash is invalid!"); + return; + } std::lock_guard lock(metaInfoMgrMutex_); for (auto &metaCapInfo : globalMetaInfoMap_) { if (IsCapKeyMatchDeviceId(metaCapInfo.first, udidHash)) { @@ -292,6 +316,10 @@ void MetaInfoManager::GetMetaCapInfosByUdidHash(const std::string &udidHash, int32_t MetaInfoManager::GetMetaCapByValue(const std::string &value, std::shared_ptr &metaCapPtr) { + if (value.empty() || value.length() > MAX_MESSAGE_LEN){ + DHLOGE("Value is invalid!"); + return ERR_DH_FWK_PARA_INVALID; + } if (metaCapPtr == nullptr) { metaCapPtr = std::make_shared(); } @@ -347,6 +375,10 @@ void MetaInfoManager::OnChange(const DistributedKv::DataOrigin &origin, Keys &&k void MetaInfoManager::HandleMetaCapabilityAddChange(const std::vector &insertRecords) { + if (insertRecords.empty() || insertRecords.size() > MAX_DB_RECORD_SIZE){ + DHLOGE("Records vector is invalide!"); + return; + } std::lock_guard lock(metaInfoMgrMutex_); for (const auto &item : insertRecords) { const std::string value = item.value.ToString(); @@ -381,6 +413,10 @@ void MetaInfoManager::HandleMetaCapabilityAddChange(const std::vector &updateRecords) { + if (updateRecords.empty() || updateRecords.size() > MAX_DB_RECORD_SIZE){ + DHLOGE("Records vector is invalide!"); + return; + } std::lock_guard lock(metaInfoMgrMutex_); for (const auto &item : updateRecords) { const std::string value = item.value.ToString(); @@ -397,6 +433,10 @@ void MetaInfoManager::HandleMetaCapabilityUpdateChange(const std::vector &deleteRecords) { + if (deleteRecords.empty() || deleteRecords.size() > MAX_DB_RECORD_SIZE){ + DHLOGE("Records vector is invalide!"); + return; + } std::lock_guard lock(metaInfoMgrMutex_); for (const auto &item : deleteRecords) { const std::string value = item.value.ToString(); @@ -413,6 +453,10 @@ void MetaInfoManager::HandleMetaCapabilityDeleteChange(const std::vector MetaInfoManager::GetEntriesByKeys(const std::vector &keys) { + if (keys.empty() || keys.size() > MAX_ARR_SIZE){ + DHLOGE("Length of vactor of keys is invalid!"); + return {}; + } DHLOGI("call"); if (keys.empty()) { DHLOGE("keys empty."); diff --git a/services/distributedhardwarefwkservice/src/resourcemanager/version_info.cpp b/services/distributedhardwarefwkservice/src/resourcemanager/version_info.cpp index 6871330b..012fcbe3 100644 --- a/services/distributedhardwarefwkservice/src/resourcemanager/version_info.cpp +++ b/services/distributedhardwarefwkservice/src/resourcemanager/version_info.cpp @@ -32,6 +32,10 @@ namespace DistributedHardware { int32_t VersionInfo::FromJsonString(const std::string &jsonStr) { + if (jsonStr.empty() || jsonStr.length() > MAX_JSON_SIZE){ + DHLOGE("Json string is invalid!"); + return ERR_DH_FWK_PARA_INVALID; + } cJSON *jsonObj = cJSON_Parse(jsonStr.c_str()); if (jsonObj == NULL) { DHLOGE("json string parse failed"); @@ -63,6 +67,10 @@ std::string VersionInfo::ToJsonString() const void ToJson(cJSON *jsonObject, const VersionInfo &versionInfo) { + if (jsonObject == nullptr) { + DHLOGE("Json pointer is nullptr!"); + return; + } cJSON_AddStringToObject(jsonObject, DEV_ID.c_str(), versionInfo.deviceId.c_str()); cJSON_AddStringToObject(jsonObject, DH_VER.c_str(), versionInfo.dhVersion.c_str()); @@ -90,6 +98,10 @@ void ToJson(cJSON *jsonObject, const VersionInfo &versionInfo) void FromJson(const cJSON *jsonObject, CompVersion &compVer) { + if (jsonObject == nullptr) { + DHLOGE("Json pointer is nullptr!"); + return; + } if (IsString(jsonObject, NAME)) { compVer.name = cJSON_GetObjectItem(jsonObject, NAME.c_str())->valuestring; } @@ -110,6 +122,10 @@ void FromJson(const cJSON *jsonObject, CompVersion &compVer) void FromJson(const cJSON *jsonObject, VersionInfo &versionInfo) { + if (jsonObject == nullptr) { + DHLOGE("Json pointer is nullptr!"); + return; + } if (IsString(jsonObject, DEV_ID)) { versionInfo.deviceId = cJSON_GetObjectItem(jsonObject, DEV_ID.c_str())->valuestring; } diff --git a/services/distributedhardwarefwkservice/src/resourcemanager/version_info_manager.cpp b/services/distributedhardwarefwkservice/src/resourcemanager/version_info_manager.cpp index b26557e6..5145db53 100644 --- a/services/distributedhardwarefwkservice/src/resourcemanager/version_info_manager.cpp +++ b/services/distributedhardwarefwkservice/src/resourcemanager/version_info_manager.cpp @@ -138,6 +138,10 @@ int32_t VersionInfoManager::AddVersion(const VersionInfo &versionInfo) int32_t VersionInfoManager::GetVersionInfoByDeviceId(const std::string &deviceId, VersionInfo &versionInfo) { + if (deviceId.empty() || deviceId.length() > MAX_ID_LEN){ + DHLOGE("Device ID is invalid!"); + return ERR_DH_FWK_PARA_INVALID; + } std::lock_guard lock(verInfoMgrMutex_); if (dbAdapterPtr_ == nullptr) { DHLOGE("dbAdapterPtr_ is null"); @@ -167,6 +171,10 @@ void VersionInfoManager::UpdateVersionCache(const VersionInfo &versionInfo) int32_t VersionInfoManager::RemoveVersionInfoByDeviceId(const std::string &deviceId) { + if (deviceId.empty() || deviceId.length() > MAX_ID_LEN){ + DHLOGE("Device ID is invalid!"); + return ERR_DH_FWK_PARA_INVALID; + } DHLOGI("Remove version device info, key: %{public}s", GetAnonyString(deviceId).c_str()); std::lock_guard lock(verInfoMgrMutex_); if (dbAdapterPtr_ == nullptr) { @@ -192,6 +200,10 @@ int32_t VersionInfoManager::RemoveVersionInfoByDeviceId(const std::string &devic int32_t VersionInfoManager::SyncVersionInfoFromDB(const std::string &deviceId) { + if (deviceId.empty() || deviceId.length() > MAX_ID_LEN){ + DHLOGE("Device ID is invalid!"); + return ERR_DH_FWK_PARA_INVALID; + } DHLOGI("Sync versionInfo from DB, deviceId: %{public}s", GetAnonyString(deviceId).c_str()); std::lock_guard lock(verInfoMgrMutex_); if (dbAdapterPtr_ == nullptr) { @@ -274,6 +286,10 @@ void VersionInfoManager::OnChange(const DistributedKv::ChangeNotification &chang void VersionInfoManager::HandleVersionAddChange(const std::vector &insertRecords) { + if (insertRecords.empty() || insertRecords.size() > MAX_DB_RECORD_SIZE){ + DHLOGE("Records vector is invalide!"); + return; + } DHLOGI("Version add change"); for (const auto &item : insertRecords) { const std::string value = item.value.ToString(); @@ -287,6 +303,10 @@ void VersionInfoManager::HandleVersionAddChange(const std::vector &updateRecords) { + if (updateRecords.empty() || updateRecords.size() > MAX_DB_RECORD_SIZE){ + DHLOGE("Records vector is invalide!"); + return; + } DHLOGI("Version update change"); for (const auto &item : updateRecords) { const std::string value = item.value.ToString(); @@ -300,6 +320,10 @@ void VersionInfoManager::HandleVersionUpdateChange(const std::vector &deleteRecords) { + if (deleteRecords.empty() || deleteRecords.size() > MAX_DB_RECORD_SIZE){ + DHLOGE("Records vector is invalide!"); + return; + } DHLOGI("Version delete change"); for (const auto &item : deleteRecords) { const std::string value = item.value.ToString(); diff --git a/services/distributedhardwarefwkservice/src/task/offline_task.cpp b/services/distributedhardwarefwkservice/src/task/offline_task.cpp index a352acb1..5ad23ce4 100644 --- a/services/distributedhardwarefwkservice/src/task/offline_task.cpp +++ b/services/distributedhardwarefwkservice/src/task/offline_task.cpp @@ -21,11 +21,9 @@ #include "anonymous_string.h" #include "capability_info_manager.h" #include "constants.h" -#include "dh_context.h" #include "dh_utils_tool.h" #include "distributed_hardware_errno.h" #include "distributed_hardware_log.h" -#include "distributed_hardware_manager_factory.h" #include "meta_info_manager.h" #include "task_board.h" #include "task_executor.h" @@ -106,8 +104,7 @@ void OffLineTask::CreateDisableTask() if (devDhInfos.empty()) { DHLOGW("Can not get cap info from CapabilityInfo, try use meta info"); std::vector> metaCapInfos; - std::string udidHash = DHContext::GetInstance().GetUdidHashIdByUUID(GetUUID()); - MetaInfoManager::GetInstance()->GetMetaCapInfosByUdidHash(udidHash, metaCapInfos); + MetaInfoManager::GetInstance()->GetMetaCapInfosByUdidHash(deviceId, metaCapInfos); std::for_each(metaCapInfos.begin(), metaCapInfos.end(), [&](std::shared_ptr cap) { devDhInfos.push_back({cap->GetDHId(), cap->GetDHType()}); }); @@ -136,12 +133,6 @@ void OffLineTask::WaitDisableTaskFinish() std::unique_lock waitLock(unFinishTaskMtx_); finishCondVar_.wait(waitLock, [&] { return this->unFinishChildrenTasks_.empty(); }); DHLOGI("all disable task finish"); - DHContext::GetInstance().RemoveOnlineDeviceByUUID(GetUUID()); - if (DHContext::GetInstance().GetOnlineCount() == 0 && - DHContext::GetInstance().GetIsomerismConnectCount() == 0) { - DHLOGI("all devices are offline, start to free the resource"); - DistributedHardwareManagerFactory::GetInstance().UnInit(); - } } void OffLineTask::ClearOffLineInfo() diff --git a/services/distributedhardwarefwkservice/src/transport/dh_comm_tool.cpp b/services/distributedhardwarefwkservice/src/transport/dh_comm_tool.cpp index 3998af7e..05df2ed0 100644 --- a/services/distributedhardwarefwkservice/src/transport/dh_comm_tool.cpp +++ b/services/distributedhardwarefwkservice/src/transport/dh_comm_tool.cpp @@ -197,7 +197,7 @@ void DHCommTool::DHCommToolEventHandler::ProcessFullCapsRsp(const FullCapsRsp &c const std::shared_ptr dhCommToolPtr) { if (capsRsp.networkId.empty() || capsRsp.caps.empty()) { - DHLOGE("Receive remote caps info invalid"); + DHLOGE("Receive remote caps info invalid!"); return; } // after receive rsp, close dsoftbus channel diff --git a/services/distributedhardwarefwkservice/src/transport/dh_transport.cpp b/services/distributedhardwarefwkservice/src/transport/dh_transport.cpp index 90a54bd7..bfae1f51 100644 --- a/services/distributedhardwarefwkservice/src/transport/dh_transport.cpp +++ b/services/distributedhardwarefwkservice/src/transport/dh_transport.cpp @@ -108,6 +108,10 @@ void DHTransport::OnBytesReceived(int32_t socketId, const void *data, uint32_t d void DHTransport::HandleReceiveMessage(const std::string &payload) { + if (payload.empty() || payload.length() > MAX_MESSAGE_LEN){ + DHLOGE("Payload is invalide!"); + return; + } std::string rawPayload = Decompress(payload); cJSON *root = cJSON_Parse(rawPayload.c_str()); @@ -126,10 +130,6 @@ void DHTransport::HandleReceiveMessage(const std::string &payload) DHLOGE("Can not get DHCommTool ptr"); return; } - if (dhCommToolSPtr->GetEventHandler() == nullptr) { - DHLOGE("Can not get eventHandler"); - return; - } dhCommToolSPtr->GetEventHandler()->SendEvent(msgEvent, 0, AppExecFwk::EventQueue::Priority::IMMEDIATE); } @@ -205,6 +205,10 @@ void OnFile(int32_t socket, FileEvent *event) void OnQos(int32_t socket, QoSEvent eventId, const QosTV *qos, uint32_t qosCount) { + if (qosCount < 0 || qosCount > MAX_ROUND_SIZE){ + DHLOGE("qosCount is invalid!"); + return; + } DHLOGI("OnQos, socket: %{public}d, QoSEvent: %{public}d, qosCount: %{public}" PRIu32, socket, (int32_t)eventId, qosCount); for (uint32_t idx = 0; idx < qosCount; idx++) { @@ -241,6 +245,10 @@ int32_t DHTransport::CreateServerSocket() int32_t DHTransport::CreateClientSocket(const std::string &remoteNetworkId) { + if (remoteNetworkId.empty() || remoteNetworkId.length() > MAX_ID_LEN){ + DHLOGE("Remote network ID is invalid!"); + return ERR_DH_FWK_PARA_INVALID; + } DHLOGI("CreateClientSocket start, peerNetworkId: %{public}s", GetAnonyString(remoteNetworkId).c_str()); std::string peerSocketName = DH_FWK_SESSION_NAME + remoteNetworkId.substr(0, INTERCEPT_STRING_LENGTH); SocketInfo info = { @@ -305,6 +313,10 @@ int32_t DHTransport::UnInit() bool DHTransport::IsDeviceSessionOpened(const std::string &remoteNetworkId, int32_t &socketId) { + if (remoteNetworkId.empty() || remoteNetworkId.length() > MAX_ID_LEN){ + DHLOGE("Remote network ID is invalid!"); + return false; + } std::lock_guard lock(rmtSocketIdMtx_); if (remoteDevSocketIds_.find(remoteNetworkId) == remoteDevSocketIds_.end()) { return false; @@ -330,12 +342,20 @@ std::string DHTransport::GetRemoteNetworkIdBySocketId(int32_t socketId) void DHTransport::ClearDeviceSocketOpened(const std::string &remoteDevId) { + if (remoteDevId.length() <= 0 || remoteDevId.length() > MAX_ID_LEN){ + DHLOGE("Remote device ID is invalide!"); + return; + } std::lock_guard lock(rmtSocketIdMtx_); remoteDevSocketIds_.erase(remoteDevId); } int32_t DHTransport::StartSocket(const std::string &remoteNetworkId) { + if (remoteNetworkId.empty() || remoteNetworkId.length() > MAX_ID_LEN){ + DHLOGE("Remote network ID is invalid!"); + return ERR_DH_FWK_PARA_INVALID; + } int32_t socketId = -1; if (IsDeviceSessionOpened(remoteNetworkId, socketId)) { DHLOGE("Softbus session has already opened, deviceId: %{public}s", GetAnonyString(remoteNetworkId).c_str()); @@ -371,6 +391,10 @@ int32_t DHTransport::StartSocket(const std::string &remoteNetworkId) int32_t DHTransport::StopSocket(const std::string &remoteNetworkId) { + if (remoteNetworkId.empty() || remoteNetworkId.length() > MAX_ID_LEN){ + DHLOGE("Remote network ID is invalid!"); + return ERR_DH_FWK_PARA_INVALID; + } int32_t socketId = -1; if (!IsDeviceSessionOpened(remoteNetworkId, socketId)) { DHLOGI("remote dev may be not opened, remoteNetworkId: %{public}s", GetAnonyString(remoteNetworkId).c_str()); @@ -386,6 +410,14 @@ int32_t DHTransport::StopSocket(const std::string &remoteNetworkId) int32_t DHTransport::Send(const std::string &remoteNetworkId, const std::string &payload) { + if (remoteNetworkId.empty() || remoteNetworkId.length() > MAX_ID_LEN){ + DHLOGE("Remote network ID is invalid!"); + return ERR_DH_FWK_PARA_INVALID; + } + if (payload.empty() || payload.length() > MAX_MESSAGE_LEN){ + DHLOGE("Payload is invalide!"); + return ERR_DH_FWK_PARA_INVALID; + } int32_t socketId = -1; if (!IsDeviceSessionOpened(remoteNetworkId, socketId)) { DHLOGI("The session is not open, target networkId: %{public}s", GetAnonyString(remoteNetworkId).c_str()); diff --git a/services/distributedhardwarefwkservice/src/transport/dh_transport_obj.cpp b/services/distributedhardwarefwkservice/src/transport/dh_transport_obj.cpp index feebd097..a1280251 100644 --- a/services/distributedhardwarefwkservice/src/transport/dh_transport_obj.cpp +++ b/services/distributedhardwarefwkservice/src/transport/dh_transport_obj.cpp @@ -17,11 +17,19 @@ #include "dh_utils_tool.h" +#include "constants.h" +#include "distributed_hardware_errno.h" +#include "distributed_hardware_log.h" + namespace OHOS { namespace DistributedHardware { void ToJson(cJSON *jsonObject, const FullCapsRsp &capsRsp) { + if (jsonObject == nullptr) { + DHLOGE("Json pointer is nullptr!"); + return; + } const char *networkId = capsRsp.networkId.c_str(); cJSON_AddStringToObject(jsonObject, CAPS_RSP_NETWORKID_KEY, networkId); cJSON *capArr = cJSON_CreateArray(); @@ -42,6 +50,10 @@ void ToJson(cJSON *jsonObject, const FullCapsRsp &capsRsp) void FromJson(const cJSON *jsonObject, FullCapsRsp &capsRsp) { + if (jsonObject == nullptr) { + DHLOGE("Json pointer is nullptr!"); + return; + } std::string keyNetworkId(CAPS_RSP_NETWORKID_KEY); if (IsString(jsonObject, keyNetworkId)) { capsRsp.networkId = cJSON_GetObjectItem(jsonObject, CAPS_RSP_NETWORKID_KEY)->valuestring; @@ -61,6 +73,10 @@ void FromJson(const cJSON *jsonObject, FullCapsRsp &capsRsp) void ToJson(cJSON *jsonObject, const CommMsg &commMsg) { + if (jsonObject == nullptr) { + DHLOGE("Json pointer is nullptr!"); + return; + } cJSON_AddNumberToObject(jsonObject, COMM_MSG_CODE_KEY, commMsg.code); const char *msg = commMsg.msg.c_str(); cJSON_AddStringToObject(jsonObject, COMM_MSG_MSG_KEY, msg); @@ -68,6 +84,10 @@ void ToJson(cJSON *jsonObject, const CommMsg &commMsg) void FromJson(const cJSON *jsonObject, CommMsg &commMsg) { + if (jsonObject == nullptr) { + DHLOGE("Json pointer is nullptr!"); + return; + } std::string keyCode(COMM_MSG_CODE_KEY); if (IsInt32(jsonObject, keyCode)) { commMsg.code = cJSON_GetObjectItem(jsonObject, COMM_MSG_CODE_KEY)->valueint; diff --git a/services/distributedhardwarefwkservice/src/utils/dh_context.cpp b/services/distributedhardwarefwkservice/src/utils/dh_context.cpp index 0959d953..bc4a2639 100644 --- a/services/distributedhardwarefwkservice/src/utils/dh_context.cpp +++ b/services/distributedhardwarefwkservice/src/utils/dh_context.cpp @@ -114,8 +114,16 @@ const DeviceInfo& DHContext::GetDeviceInfo() void DHContext::AddOnlineDevice(const std::string &udid, const std::string &uuid, const std::string &networkId) { - if (udid.empty() || uuid.empty() || networkId.empty()) { - DHLOGE("Add online device id invalid"); + if (networkId.empty() || networkId.length() > MAX_ID_LEN){ + DHLOGE("Network ID is invalid!"); + return; + } + if ( uuid.empty() || uuid.length() > MAX_ID_LEN ){ + DHLOGE("UUID is invalid!"); + return; + } + if ( udid.empty() || udid.length() > MAX_ID_LEN ){ + DHLOGE("UDID is invalid!"); return; } std::unique_lock lock(onlineDevMutex_); @@ -137,6 +145,10 @@ void DHContext::AddOnlineDevice(const std::string &udid, const std::string &uuid void DHContext::RemoveOnlineDeviceByUUID(const std::string &uuid) { + if ( uuid.empty() || uuid.length() > MAX_ID_LEN ){ + DHLOGE("UUID is invalid!"); + return; + } std::unique_lock lock(onlineDevMutex_); for (auto iter = devIdEntrySet_.begin(); iter != devIdEntrySet_.end(); iter++) { if (iter->uuid == uuid) { @@ -148,6 +160,10 @@ void DHContext::RemoveOnlineDeviceByUUID(const std::string &uuid) bool DHContext::IsDeviceOnline(const std::string &uuid) { + if ( uuid.empty() || uuid.length() > MAX_ID_LEN ){ + DHLOGE("UUID is invalid!"); + return false; + } if (uuid.empty()) { return false; } @@ -170,6 +186,11 @@ size_t DHContext::GetOnlineCount() std::string DHContext::GetNetworkIdByUUID(const std::string &uuid) { + if ( uuid.length() <= 0 || uuid.length() > MAX_ID_LEN ) + { + DHLOGD("UUID is invalid!"); + return ""; + } std::unique_lock lock(onlineDevMutex_); std::string networkId = ""; for (auto iter = devIdEntrySet_.begin(); iter != devIdEntrySet_.end(); iter++) { @@ -183,6 +204,10 @@ std::string DHContext::GetNetworkIdByUUID(const std::string &uuid) std::string DHContext::GetUdidHashIdByUUID(const std::string &uuid) { + if ( uuid.empty() || uuid.length() > MAX_ID_LEN ){ + DHLOGE("UUID is invalid!"); + return ""; + } std::unique_lock lock(onlineDevMutex_); std::string udidHash = ""; for (auto iter = devIdEntrySet_.begin(); iter != devIdEntrySet_.end(); iter++) { @@ -196,6 +221,10 @@ std::string DHContext::GetUdidHashIdByUUID(const std::string &uuid) std::string DHContext::GetUUIDByNetworkId(const std::string &networkId) { + if (networkId.empty() || networkId.length() > MAX_ID_LEN){ + DHLOGE("Network ID is invalid!"); + return ""; + } std::unique_lock lock(onlineDevMutex_); std::string uuid = ""; for (auto iter = devIdEntrySet_.begin(); iter != devIdEntrySet_.end(); iter++) { @@ -209,6 +238,10 @@ std::string DHContext::GetUUIDByNetworkId(const std::string &networkId) std::string DHContext::GetUDIDByNetworkId(const std::string &networkId) { + if (networkId.empty() || networkId.length() > MAX_ID_LEN){ + DHLOGE("Network ID is invalid!"); + return ""; + } std::unique_lock lock(onlineDevMutex_); std::string udid = ""; for (auto iter = devIdEntrySet_.begin(); iter != devIdEntrySet_.end(); iter++) { @@ -222,6 +255,10 @@ std::string DHContext::GetUDIDByNetworkId(const std::string &networkId) std::string DHContext::GetUUIDByDeviceId(const std::string &deviceId) { + if (deviceId.empty() || deviceId.length() > MAX_ID_LEN){ + DHLOGE("Device ID is invalid!"); + return ""; + } std::unique_lock lock(onlineDevMutex_); std::string uuid = ""; for (auto iter = devIdEntrySet_.begin(); iter != devIdEntrySet_.end(); iter++) { @@ -235,6 +272,10 @@ std::string DHContext::GetUUIDByDeviceId(const std::string &deviceId) std::string DHContext::GetNetworkIdByDeviceId(const std::string &deviceId) { + if (deviceId.empty() || deviceId.length() > MAX_ID_LEN){ + DHLOGE("Device ID is invalid!"); + return ""; + } std::unique_lock lock(onlineDevMutex_); std::string networkId = ""; for (auto iter = devIdEntrySet_.begin(); iter != devIdEntrySet_.end(); iter++) { @@ -246,8 +287,12 @@ std::string DHContext::GetNetworkIdByDeviceId(const std::string &deviceId) return networkId; } -std::string DHContext::GetDeviceIdByDBGetPrefix(const std::string &prefix) +std::string DHContext::GetDeviceIdByDBGetPrefix(const std::string &prefix) /// max length of prefix { + if (prefix.empty() || prefix.length() > MAX_ID_LEN){ + DHLOGE("ID prefix is invalid!"); + return ""; + } std::string id = ""; if (prefix.empty()) { return id; @@ -274,6 +319,10 @@ void DHContext::RegisDHFWKIsomerismListener() void DHContext::DHFWKIsomerismListener::OnMessage(const DHTopic topic, const std::string &message) { + if ( message.length() <= 0 || message.length() > MAX_MESSAGE_LEN ){ + DHLOGE("Message is invalide!"); + return; + } DHLOGI("OnMessage topic: %{public}u", static_cast(topic)); if (topic != DHTopic::TOPIC_ISOMERISM) { DHLOGE("OnMessage topic is wrong"); @@ -313,6 +362,10 @@ void DHContext::DHFWKIsomerismListener::OnMessage(const DHTopic topic, const std void DHContext::AddIsomerismConnectDev(const std::string &IsomerismDeviceId) { + if (IsomerismDeviceId.length() <=0 || IsomerismDeviceId.length() > MAX_ID_LEN){ + DHLOGE("Isomerism device ID is invalide!"); + return; + } DHLOGI("AddIsomerismConnectDev id = %{public}s", GetAnonyString(IsomerismDeviceId).c_str()); std::shared_lock lock(connectDevMutex_); connectedDevIds_.insert(IsomerismDeviceId); @@ -320,6 +373,10 @@ void DHContext::AddIsomerismConnectDev(const std::string &IsomerismDeviceId) void DHContext::DelIsomerismConnectDev(const std::string &IsomerismDeviceId) { + if (IsomerismDeviceId.length() <=0 || IsomerismDeviceId.length() > MAX_ID_LEN){ + DHLOGE("Isomerism device ID is invalide!"); + return; + } DHLOGI("DelIsomerismConnectDev id = %{public}s", GetAnonyString(IsomerismDeviceId).c_str()); std::shared_lock lock(connectDevMutex_); if (connectedDevIds_.find(IsomerismDeviceId) == connectedDevIds_.end()) { diff --git a/services/distributedhardwarefwkservice/src/versionmanager/version_manager.cpp b/services/distributedhardwarefwkservice/src/versionmanager/version_manager.cpp index 8cd7b034..36c76140 100644 --- a/services/distributedhardwarefwkservice/src/versionmanager/version_manager.cpp +++ b/services/distributedhardwarefwkservice/src/versionmanager/version_manager.cpp @@ -60,6 +60,10 @@ void VersionManager::ShowLocalVersion(const DHVersion &dhVersion) const int32_t VersionManager::AddDHVersion(const std::string &uuid, const DHVersion &dhVersion) { + if ( uuid.empty() || uuid.length() > MAX_ID_LEN ){ + DHLOGE("UUID is invalid!"); + return ERR_DH_FWK_PARA_INVALID; + } DHLOGI("addDHVersion uuid: %{public}s", GetAnonyString(uuid).c_str()); std::lock_guard lock(versionMutex_); dhVersions_[uuid] = dhVersion; @@ -68,6 +72,10 @@ int32_t VersionManager::AddDHVersion(const std::string &uuid, const DHVersion &d int32_t VersionManager::RemoveDHVersion(const std::string &uuid) { + if ( uuid.empty() || uuid.length() > MAX_ID_LEN ){ + DHLOGE("UUID is invalid!"); + return ERR_DH_FWK_PARA_INVALID; + } DHLOGI("uuid: %{public}s", GetAnonyString(uuid).c_str()); std::lock_guard lock(versionMutex_); std::unordered_map::iterator iter = dhVersions_.find(uuid); @@ -81,6 +89,10 @@ int32_t VersionManager::RemoveDHVersion(const std::string &uuid) int32_t VersionManager::GetDHVersion(const std::string &uuid, DHVersion &dhVersion) { + if ( uuid.empty() || uuid.length() > MAX_ID_LEN ){ + DHLOGE("UUID is invalid!"); + return ERR_DH_FWK_PARA_INVALID; + } DHLOGI("uuid: %{public}s", GetAnonyString(uuid).c_str()); std::lock_guard lock(versionMutex_); std::unordered_map::iterator iter = dhVersions_.find(uuid); @@ -95,6 +107,10 @@ int32_t VersionManager::GetDHVersion(const std::string &uuid, DHVersion &dhVersi int32_t VersionManager::GetCompVersion(const std::string &uuid, const DHType dhType, CompVersion &compVersion) { + if ( uuid.empty() || uuid.length() > MAX_ID_LEN ){ + DHLOGE("UUID is invalid!"); + return ERR_DH_FWK_PARA_INVALID; + } DHVersion dhVersion; int32_t ret = GetDHVersion(uuid, dhVersion); if (ret != DH_FWK_SUCCESS) { diff --git a/services/distributedhardwarefwkservice/test/unittest/common/localhardwaremanager/pluginlistenerimpl/src/mock_hardware_handler.cpp b/services/distributedhardwarefwkservice/test/unittest/common/localhardwaremanager/pluginlistenerimpl/src/mock_hardware_handler.cpp index ef388b0d..8dc8f3a4 100644 --- a/services/distributedhardwarefwkservice/test/unittest/common/localhardwaremanager/pluginlistenerimpl/src/mock_hardware_handler.cpp +++ b/services/distributedhardwarefwkservice/test/unittest/common/localhardwaremanager/pluginlistenerimpl/src/mock_hardware_handler.cpp @@ -15,6 +15,8 @@ #include "mock_hardware_handler.h" +#include "constants.h" +#include "distributed_hardware_log.h" #include "distributed_hardware_errno.h" namespace OHOS { @@ -60,6 +62,10 @@ void MockHardwareHandler::UnRegisterPluginListener() int32_t MockHardwareHandler::PluginHardware(const std::string &dhId, const std::string &attr, const std::string &subtype) { + if (dhId.empty() || dhId.length() > MAX_ID_LEN){ + DHLOGE("DHID is invalide!"); + return ERR_DH_FWK_PARA_INVALID; + } if (listener_ != nullptr) { listener_->PluginHardware(dhId, attr, subtype); } @@ -68,6 +74,10 @@ int32_t MockHardwareHandler::PluginHardware(const std::string &dhId, const std:: int32_t MockHardwareHandler::UnPluginHardware(const std::string &dhId) { + if (udidHash.length() <= 0 || udidHash.length() > MAX_HASH_SIZE){ + DHLOGE("UDID hash value is invalid!"); + return ERR_DH_FWK_PARA_INVALID; + } if (listener_ != nullptr) { listener_->UnPluginHardware(dhId); } diff --git a/utils/src/anonymous_string.cpp b/utils/src/anonymous_string.cpp index c5491d12..44073564 100644 --- a/utils/src/anonymous_string.cpp +++ b/utils/src/anonymous_string.cpp @@ -20,6 +20,10 @@ #include "securec.h" +#include "constants.h" +#include "distributed_hardware_errno.h" +#include "distributed_hardware_log.h" + namespace OHOS { namespace DistributedHardware { namespace { @@ -30,7 +34,8 @@ namespace { } std::string GetAnonyString(const std::string &value) { - if (value.empty()) { + if (value.empty() || value.length() > MAX_MESSAGE_LEN){ + DHLOGE("Value is invalid!"); return ""; } std::string res; diff --git a/utils/src/dh_utils_tool.cpp b/utils/src/dh_utils_tool.cpp index be684494..53980f83 100644 --- a/utils/src/dh_utils_tool.cpp +++ b/utils/src/dh_utils_tool.cpp @@ -82,7 +82,8 @@ std::string GetRandomID() std::string GetUUIDByDm(const std::string &networkId) { - if (networkId.empty()) { + if (networkId.empty() || networkId.length() > MAX_ID_LEN){ + DHLOGE("Network ID is invalid!"); return ""; } std::string uuid = ""; @@ -92,7 +93,8 @@ std::string GetUUIDByDm(const std::string &networkId) std::string GetUDIDByDm(const std::string &networkId) { - if (networkId.empty()) { + if (networkId.empty() || networkId.length() > MAX_ID_LEN){ + DHLOGE("Network ID is invalid!"); return ""; } std::string udid = ""; @@ -102,8 +104,8 @@ std::string GetUDIDByDm(const std::string &networkId) std::string GetDeviceIdByUUID(const std::string &uuid) { - if (uuid.size() == 0 || uuid.size() > MAX_ID_LEN) { - DHLOGE("uuid is invalid!"); + if ( uuid.empty() || uuid.length() > MAX_ID_LEN ){ + DHLOGE("UUID is invalid!"); return ""; } return Sha256(uuid); diff --git a/utils/src/histreamer_ability_parser.cpp b/utils/src/histreamer_ability_parser.cpp index a9631116..826f9e40 100644 --- a/utils/src/histreamer_ability_parser.cpp +++ b/utils/src/histreamer_ability_parser.cpp @@ -18,6 +18,7 @@ #include "distributed_hardware_log.h" + namespace OHOS { namespace DistributedHardware { @@ -37,6 +38,10 @@ static const std::string VIDEO_BIT_STREAM_FMT = "vd_bit_stream_fmt"; void FromJson(const cJSON *jsonObject, AudioEncoderIn &audioEncoderIn) { + if (jsonObject == nullptr) { + DHLOGE("Json pointer is nullptr!"); + return; + } if (!IsString(jsonObject, MIME)) { DHLOGE("AudioEncoderIn MIME is invalid!\n"); return; @@ -59,26 +64,30 @@ void FromJson(const cJSON *jsonObject, AudioEncoderIn &audioEncoderIn) void FromJson(const cJSON *jsonObject, AudioEncoderOut &audioEncoderOut) { + if (jsonObject == nullptr) { + DHLOGE("Json pointer is nullptr!"); + return; + } if (!IsString(jsonObject, MIME)) { DHLOGE("AudioEncoderOut MIME is invalid!"); return; } audioEncoderOut.mime = cJSON_GetObjectItem(jsonObject, MIME.c_str())->valuestring; if (!IsUInt32(jsonObject, AD_MPEG_VER)) { - DHLOGE("AudioEncoderOut AD_MPEG_VER is invalid"); + DHLOGE("AudioEncoderOut AD_MPEG_VER is invalid!"); return; } audioEncoderOut.ad_mpeg_ver = (uint32_t)cJSON_GetObjectItem(jsonObject, AD_MPEG_VER.c_str())->valuedouble; if (!IsUInt8(jsonObject, AUDIO_AAC_PROFILE)) { - DHLOGE("AudioEncoderOut AUDIO_AAC_PROFILE is invalid"); + DHLOGE("AudioEncoderOut AUDIO_AAC_PROFILE is invalid!"); return; } audioEncoderOut.aac_profile = (AudioAacProfile)cJSON_GetObjectItem(jsonObject, AUDIO_AAC_PROFILE.c_str())->valuedouble; if (!IsUInt8(jsonObject, AUDIO_AAC_STREAM_FORMAT)) { - DHLOGE("AudioEncoderOut AUDIO_AAC_STREAM_FORMAT is invalid"); + DHLOGE("AudioEncoderOut AUDIO_AAC_STREAM_FORMAT is invalid!"); return; } audioEncoderOut.aac_stm_fmt = @@ -87,14 +96,18 @@ void FromJson(const cJSON *jsonObject, AudioEncoderOut &audioEncoderOut) void FromJson(const cJSON *jsonObject, AudioEncoder &audioEncoder) { + if (jsonObject == nullptr) { + DHLOGE("Json pointer is nullptr!"); + return; + } if (!IsString(jsonObject, NAME)) { - DHLOGE("AudioEncoder NAME is invalid"); + DHLOGE("AudioEncoder NAME is invalid!"); return; } audioEncoder.name = cJSON_GetObjectItem(jsonObject, NAME.c_str())->valuestring; if (!IsArray(jsonObject, INS)) { - DHLOGE("AudioEncoder INS is invalid"); + DHLOGE("AudioEncoder INS is invalid!"); return; } cJSON *insJson = cJSON_GetObjectItem(jsonObject, INS.c_str()); @@ -106,7 +119,7 @@ void FromJson(const cJSON *jsonObject, AudioEncoder &audioEncoder) } if (!IsArray(jsonObject, OUTS)) { - DHLOGE("AudioEncoder OUTS is invalid"); + DHLOGE("AudioEncoder OUTS is invalid!"); return; } cJSON *outsJson = cJSON_GetObjectItem(jsonObject, OUTS.c_str()); @@ -120,14 +133,18 @@ void FromJson(const cJSON *jsonObject, AudioEncoder &audioEncoder) void FromJson(const cJSON *jsonObject, AudioDecoderIn &audioDecoderIn) { + if (jsonObject == nullptr) { + DHLOGE("Json pointer is nullptr!"); + return; + } if (!IsString(jsonObject, MIME)) { - DHLOGE("AudioDecoderIn MIME is invalid"); + DHLOGE("AudioDecoderIn MIME is invalid!"); return; } audioDecoderIn.mime = cJSON_GetObjectItem(jsonObject, MIME.c_str())->valuestring; if (!IsArray(jsonObject, AUDIO_CHANNEL_LAYOUT)) { - DHLOGE("AudioDecoder AUDIO_CHANNEL_LAYOUT is invalid"); + DHLOGE("AudioDecoder AUDIO_CHANNEL_LAYOUT is invalid!"); return; } const cJSON *channelLayoutJson = cJSON_GetObjectItem(jsonObject, AUDIO_CHANNEL_LAYOUT.c_str()); @@ -139,13 +156,17 @@ void FromJson(const cJSON *jsonObject, AudioDecoderIn &audioDecoderIn) void FromJson(const cJSON *jsonObject, AudioDecoderOut &audioDecoderOut) { + if (jsonObject == nullptr) { + DHLOGE("Json pointer is nullptr!"); + return; + } if (!IsString(jsonObject, MIME)) { - DHLOGE("AudioDecoderOut MIME is invalid"); + DHLOGE("AudioDecoderOut MIME is invalid!"); return; } audioDecoderOut.mime = cJSON_GetObjectItem(jsonObject, MIME.c_str())->valuestring; if (!IsArray(jsonObject, AUDIO_SAMPLE_FORMAT)) { - DHLOGE("AudioDecoderOut AUDIO_SAMPLE_FORMAT is invalid"); + DHLOGE("AudioDecoderOut AUDIO_SAMPLE_FORMAT is invalid!"); return; } cJSON *sampleFormatJson = cJSON_GetObjectItem(jsonObject, AUDIO_SAMPLE_FORMAT.c_str()); @@ -157,14 +178,18 @@ void FromJson(const cJSON *jsonObject, AudioDecoderOut &audioDecoderOut) void FromJson(const cJSON *jsonObject, AudioDecoder &audioDecoder) { + if (jsonObject == nullptr) { + DHLOGE("Json pointer is nullptr!"); + return; + } if (!IsString(jsonObject, NAME)) { - DHLOGE("AudioDecoderOut MIME is invalid"); + DHLOGE("AudioDecoderOut MIME is invalid!"); return; } audioDecoder.name = cJSON_GetObjectItem(jsonObject, NAME.c_str())->valuestring; if (!IsArray(jsonObject, INS)) { - DHLOGE("AudioDecoder OUTS is invalid"); + DHLOGE("AudioDecoder OUTS is invalid!"); return; } const cJSON *insJson = cJSON_GetObjectItem(jsonObject, INS.c_str()); @@ -175,7 +200,7 @@ void FromJson(const cJSON *jsonObject, AudioDecoder &audioDecoder) audioDecoder.ins.push_back(in); } if (!IsArray(jsonObject, OUTS)) { - DHLOGE("AudioDecoder OUTS is invalid"); + DHLOGE("AudioDecoder OUTS is invalid!"); return; } cJSON *outsJson = cJSON_GetObjectItem(jsonObject, OUTS.c_str()); @@ -189,14 +214,18 @@ void FromJson(const cJSON *jsonObject, AudioDecoder &audioDecoder) void FromJson(const cJSON *jsonObject, VideoEncoderIn &videoEncoderIn) { + if (jsonObject == nullptr) { + DHLOGE("Json pointer is nullptr!"); + return; + } if (!IsString(jsonObject, MIME)) { - DHLOGE("VideoEncoderIn MIME is invalid"); + DHLOGE("VideoEncoderIn MIME is invalid!"); return; } videoEncoderIn.mime = cJSON_GetObjectItem(jsonObject, MIME.c_str())->valuestring; if (!IsArray(jsonObject, VIDEO_PIXEL_FMT)) { - DHLOGE("VideoEncoderIn VIDEO_PIXEL_FMT is invalid"); + DHLOGE("VideoEncoderIn VIDEO_PIXEL_FMT is invalid!"); return; } cJSON *videoPixelFmt = cJSON_GetObjectItem(jsonObject, VIDEO_PIXEL_FMT.c_str()); @@ -208,8 +237,12 @@ void FromJson(const cJSON *jsonObject, VideoEncoderIn &videoEncoderIn) void FromJson(const cJSON *jsonObject, VideoEncoderOut &videoEncoderOut) { + if (jsonObject == nullptr) { + DHLOGE("Json pointer is nullptr!"); + return; + } if (!IsString(jsonObject, MIME)) { - DHLOGE("VideoEncoderIn MIME is invalid"); + DHLOGE("VideoEncoderIn MIME is invalid!"); return; } videoEncoderOut.mime = cJSON_GetObjectItem(jsonObject, MIME.c_str())->valuestring; @@ -217,14 +250,18 @@ void FromJson(const cJSON *jsonObject, VideoEncoderOut &videoEncoderOut) void FromJson(const cJSON *jsonObject, VideoEncoder &videoEncoder) { + if (jsonObject == nullptr) { + DHLOGE("Json pointer is nullptr!"); + return; + } if (!IsString(jsonObject, NAME)) { - DHLOGE("VideoEncoder NAME is invalid"); + DHLOGE("VideoEncoder NAME is invalid!"); return; } videoEncoder.name = cJSON_GetObjectItem(jsonObject, NAME.c_str())->valuestring; if (!IsArray(jsonObject, INS)) { - DHLOGE("VideoEncoder INS is invalid"); + DHLOGE("VideoEncoder INS is invalid!"); return; } cJSON *videoEncoderInsJson = cJSON_GetObjectItem(jsonObject, INS.c_str()); @@ -236,7 +273,7 @@ void FromJson(const cJSON *jsonObject, VideoEncoder &videoEncoder) } if (!IsArray(jsonObject, OUTS)) { - DHLOGE("VideoEncoder OUTS is invalid"); + DHLOGE("VideoEncoder OUTS is invalid!"); return; } cJSON *videoEncoderOutsJson = cJSON_GetObjectItem(jsonObject, OUTS.c_str()); @@ -250,14 +287,18 @@ void FromJson(const cJSON *jsonObject, VideoEncoder &videoEncoder) void FromJson(const cJSON *jsonObject, VideoDecoderIn &videoDecoderIn) { + if (jsonObject == nullptr) { + DHLOGE("Json pointer is nullptr!"); + return; + } if (!IsString(jsonObject, MIME)) { - DHLOGE("VideoDecoderIn MIME is invalid"); + DHLOGE("VideoDecoderIn MIME is invalid!"); return; } videoDecoderIn.mime = cJSON_GetObjectItem(jsonObject, MIME.c_str())->valuestring; if (!IsArray(jsonObject, VIDEO_BIT_STREAM_FMT)) { - DHLOGE("VideoDecoderIn VIDEO_BIT_STREAM_FMT is invalid"); + DHLOGE("VideoDecoderIn VIDEO_BIT_STREAM_FMT is invalid!"); return; } cJSON *videoBitStreamFmtJson = cJSON_GetObjectItem(jsonObject, VIDEO_BIT_STREAM_FMT.c_str()); @@ -269,14 +310,18 @@ void FromJson(const cJSON *jsonObject, VideoDecoderIn &videoDecoderIn) void FromJson(const cJSON *jsonObject, VideoDecoderOut &videoDecoderOut) { + if (jsonObject == nullptr) { + DHLOGE("Json pointer is nullptr!"); + return; + } if (!IsString(jsonObject, MIME)) { - DHLOGE("VideoDecoderOut MIME is invalid"); + DHLOGE("VideoDecoderOut MIME is invalid!"); return; } videoDecoderOut.mime = cJSON_GetObjectItem(jsonObject, MIME.c_str())->valuestring; if (!IsArray(jsonObject, VIDEO_BIT_STREAM_FMT)) { - DHLOGE("videoDecoderOut VIDEO_PIXEL_FMT is invalid"); + DHLOGE("videoDecoderOut VIDEO_PIXEL_FMT is invalid!"); return; } cJSON *videoPixelFmtJson = cJSON_GetObjectItem(jsonObject, VIDEO_PIXEL_FMT.c_str()); @@ -288,14 +333,18 @@ void FromJson(const cJSON *jsonObject, VideoDecoderOut &videoDecoderOut) void FromJson(const cJSON *jsonObject, VideoDecoder &videoDecoder) { + if (jsonObject == nullptr) { + DHLOGE("Json pointer is nullptr!"); + return; + } if (!IsString(jsonObject, NAME)) { - DHLOGE("VideoDecoder NAME is invalid"); + DHLOGE("VideoDecoder NAME is invalid!"); return; } videoDecoder.name = cJSON_GetObjectItem(jsonObject, NAME.c_str())->valuestring; if (!IsArray(jsonObject, INS)) { - DHLOGE("VideoDecoder INS is invalid"); + DHLOGE("VideoDecoder INS is invalid!"); return; } cJSON *videoDecoderInsJson = cJSON_GetObjectItem(jsonObject, INS.c_str()); @@ -307,7 +356,7 @@ void FromJson(const cJSON *jsonObject, VideoDecoder &videoDecoder) } if (!IsArray(jsonObject, OUTS)) { - DHLOGE("VideoDecoder OUTS is invalid"); + DHLOGE("VideoDecoder OUTS is invalid!"); return; } cJSON *videoDecoderOutsJson = cJSON_GetObjectItem(jsonObject, OUTS.c_str()); @@ -322,6 +371,10 @@ void FromJson(const cJSON *jsonObject, VideoDecoder &videoDecoder) template void FromJson(const std::string &key, const cJSON *jsonObject, std::vector &objs) { + if (jsonObject == nullptr) { + DHLOGE("Json pointer is nullptr!"); + return; + } cJSON *json = cJSON_GetObjectItem(jsonObject, key.c_str()); if (json == NULL) { DHLOGE("JSONObject key invalid, key: %{public}s", key.c_str()); diff --git a/utils/src/histreamer_query_tool.cpp b/utils/src/histreamer_query_tool.cpp index 95131124..93269798 100644 --- a/utils/src/histreamer_query_tool.cpp +++ b/utils/src/histreamer_query_tool.cpp @@ -38,7 +38,7 @@ const std::string QueryAudioDecoderFuncName = "QueryAudioDecoderAbilityStr"; const std::string QueryVideoEncoderFuncName = "QueryVideoEncoderAbilityStr"; const std::string QueryVideoDecoderFuncName = "QueryVideoDecoderAbilityStr"; -const uint32_t MAX_MESSAGES_LEN = 1 * 1024 * 1024; +const uint32_t MAX_MESSAGE_LEN = 1 * 1024 * 1024; #ifdef __LP64__ const std::string LIB_LOAD_PATH = "/system/lib64/libhistreamer_ability_querier.z.so"; @@ -104,7 +104,7 @@ std::string HiStreamerQueryTool::QueryHiStreamerPluginInfo(HISTREAM_PLUGIN_TYPE } int32_t len = 0; - char* res = reinterpret_cast(malloc(MAX_MESSAGES_LEN)); + char* res = reinterpret_cast(malloc(MAX_MESSAGE_LEN)); if (res == nullptr) { DHLOGE("Malloc memory failed"); return ""; -- Gitee From bd910dd15586be14a2c86506888d336f8f5e8369 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=A1=8C=E5=A2=9E?= Date: Wed, 17 Jul 2024 03:16:53 +0000 Subject: [PATCH 2/2] =?UTF-8?q?=E5=88=A0=E9=99=A4=E6=96=87=E4=BB=B6=20.vsc?= =?UTF-8?q?ode?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .vscode/settings.json | 85 ------------------------------------------- 1 file changed, 85 deletions(-) delete mode 100644 .vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json deleted file mode 100644 index 37120737..00000000 --- a/.vscode/settings.json +++ /dev/null @@ -1,85 +0,0 @@ -{ - "files.associations": { - "xstring": "cpp", - "algorithm": "cpp", - "array": "cpp", - "atomic": "cpp", - "bit": "cpp", - "cctype": "cpp", - "charconv": "cpp", - "chrono": "cpp", - "cinttypes": "cpp", - "clocale": "cpp", - "cmath": "cpp", - "compare": "cpp", - "concepts": "cpp", - "condition_variable": "cpp", - "cstddef": "cpp", - "cstdint": "cpp", - "cstdio": "cpp", - "cstdlib": "cpp", - "cstring": "cpp", - "ctime": "cpp", - "cwchar": "cpp", - "deque": "cpp", - "exception": "cpp", - "format": "cpp", - "forward_list": "cpp", - "fstream": "cpp", - "functional": "cpp", - "future": "cpp", - "initializer_list": "cpp", - "iomanip": "cpp", - "ios": "cpp", - "iosfwd": "cpp", - "iostream": "cpp", - "istream": "cpp", - "iterator": "cpp", - "limits": "cpp", - "list": "cpp", - "locale": "cpp", - "map": "cpp", - "memory": "cpp", - "mutex": "cpp", - "new": "cpp", - "optional": "cpp", - "ostream": "cpp", - "queue": "cpp", - "random": "cpp", - "ranges": "cpp", - "ratio": "cpp", - "set": "cpp", - "shared_mutex": "cpp", - "span": "cpp", - "sstream": "cpp", - "stdexcept": "cpp", - "stop_token": "cpp", - "streambuf": "cpp", - "string": "cpp", - "system_error": "cpp", - "thread": "cpp", - "tuple": "cpp", - "type_traits": "cpp", - "typeinfo": "cpp", - "unordered_map": "cpp", - "unordered_set": "cpp", - "utility": "cpp", - "vector": "cpp", - "xfacet": "cpp", - "xhash": "cpp", - "xiosbase": "cpp", - "xlocale": "cpp", - "xlocbuf": "cpp", - "xlocinfo": "cpp", - "xlocmes": "cpp", - "xlocmon": "cpp", - "xlocnum": "cpp", - "xloctime": "cpp", - "xmemory": "cpp", - "xtr1common": "cpp", - "xtree": "cpp", - "xutility": "cpp", - "coroutine": "cpp", - "resumable": "cpp" - } -} \ No newline at end of file -- Gitee