From e57c4b5d01aa1d0e68859f2c642fe092c99a074a Mon Sep 17 00:00:00 2001 From: wangyb0625 Date: Wed, 16 Mar 2022 17:48:47 +0800 Subject: [PATCH 1/5] =?UTF-8?q?=E5=86=85=E6=BA=90=E9=97=AE=E9=A2=98?= =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wangyb0625 --- display/@ohos.distributedHardware.deviceManager.d.ts | 2 +- .../kits/js/src/native_devicemanager_js.cpp | 2 +- ext/mini/sa_profile/4802.xml | 2 +- .../src/auth/hichain_connector.cpp | 2 +- .../src/message/msg_request_auth.cpp | 2 +- .../devicemanagerservice/src/timer/dm_timer.cpp | 1 - ext/mini/test/unittest/device_manager_impl_test.cpp | 1 + interfaces/kits/js/src/native_devicemanager_js.cpp | 4 ++-- .../src/ipc/lite/ipc_server_stub.cpp | 4 ++-- test/unittest/device_manager_impl_test.cpp | 1 + test/unittest/mock/device_auth.cpp | 8 +++++++- test/unittest/mock/ipc_server_listener.cpp | 4 +++- test/unittest/mock/parameter.cpp | 12 +++++++++++- test/unittest/mock/softbus_bus_center.cpp | 12 +++++++++++- utils/src/dm_log.cpp | 8 +++++--- 15 files changed, 48 insertions(+), 17 deletions(-) diff --git a/display/@ohos.distributedHardware.deviceManager.d.ts b/display/@ohos.distributedHardware.deviceManager.d.ts index d00376306..791537728 100644 --- a/display/@ohos.distributedHardware.deviceManager.d.ts +++ b/display/@ohos.distributedHardware.deviceManager.d.ts @@ -16,7 +16,7 @@ import { AsyncCallback, Callback } from './basic'; /** - * Providers interfaces to creat a {@link deviceManager} instances. + * Providers interfaces to create a {@link deviceManager} instances. * * @since 7 * @Syscap SystemCapability.DISTRIBUTEDHARDWARE.deviceManager diff --git a/ext/mini/interfaces_mini/kits/js/src/native_devicemanager_js.cpp b/ext/mini/interfaces_mini/kits/js/src/native_devicemanager_js.cpp index d24031c7f..21294ccd0 100644 --- a/ext/mini/interfaces_mini/kits/js/src/native_devicemanager_js.cpp +++ b/ext/mini/interfaces_mini/kits/js/src/native_devicemanager_js.cpp @@ -544,7 +544,7 @@ void DeviceManagerModule::JsToDmBuffer(const JSIValue &object, data = JSI::GetTypedArrayInfo(field, type, length, buffer, offset); if (type != TypedArrayType::JSI_UINT8_ARRAY || length == 0 || data == nullptr) { - DMLOG(DM_LOG_ERROR, "Invaild AppIconInfo"); + DMLOG(DM_LOG_ERROR, "Invalid AppIconInfo"); return; } *bufferPtr = (uint8_t*)calloc(sizeof(uint8_t), length); diff --git a/ext/mini/sa_profile/4802.xml b/ext/mini/sa_profile/4802.xml index fce565731..8d2da2ed9 100644 --- a/ext/mini/sa_profile/4802.xml +++ b/ext/mini/sa_profile/4802.xml @@ -19,7 +19,7 @@ 4802 libdevicemanagerservice.z.so - + true false 1 diff --git a/ext/mini/services/devicemanagerservice/src/auth/hichain_connector.cpp b/ext/mini/services/devicemanagerservice/src/auth/hichain_connector.cpp index 55e986ac4..6fa2b1966 100644 --- a/ext/mini/services/devicemanagerservice/src/auth/hichain_connector.cpp +++ b/ext/mini/services/devicemanagerservice/src/auth/hichain_connector.cpp @@ -217,7 +217,7 @@ void HichainConnector::RegisterConnectorCallback(std::shared_ptr(outLen) > tempBufLen) { - DMLOG(DM_LOG_ERROR, "MbedtlsBase64Decode failed, ret %d, outLen %d, tempBufLen %d", + DMLOG(DM_LOG_ERROR, "MbedtlsBase64Decode failed, ret %d, outLen %zu, tempBufLen %d", ret, outLen, tempBufLen); outBufferLen = 0; *outBuffer = nullptr; diff --git a/ext/mini/services/devicemanagerservice/src/timer/dm_timer.cpp b/ext/mini/services/devicemanagerservice/src/timer/dm_timer.cpp index 65b138fe8..c455824c5 100644 --- a/ext/mini/services/devicemanagerservice/src/timer/dm_timer.cpp +++ b/ext/mini/services/devicemanagerservice/src/timer/dm_timer.cpp @@ -91,7 +91,6 @@ int32_t DmTimer::CreateTimeFd() void DmTimer::Release() { - DMLOG(DM_LOG_INFO, "DmTimer %s Release in", mTimerName_.c_str()); if (mStatus_ == DmTimerStatus::DM_STATUS_INIT) { DMLOG(DM_LOG_INFO, "DmTimer %s already Release", mTimerName_.c_str()); return; diff --git a/ext/mini/test/unittest/device_manager_impl_test.cpp b/ext/mini/test/unittest/device_manager_impl_test.cpp index b0073fdec..789f2b2d3 100644 --- a/ext/mini/test/unittest/device_manager_impl_test.cpp +++ b/ext/mini/test/unittest/device_manager_impl_test.cpp @@ -180,6 +180,7 @@ void DeviceDiscoverCallback::OnDiscoverFailed(uint16_t subscribeId, int32_t fail void DeviceDiscoverCallback::OnDeviceFound(uint16_t subscribeId, const DmDeviceInfo &deviceInfo) { (void)subscribeId; + (void)deviceInfo; } } // namespace Vsync } // namespace OHOS diff --git a/interfaces/kits/js/src/native_devicemanager_js.cpp b/interfaces/kits/js/src/native_devicemanager_js.cpp index e07993ec5..4e1e80c3c 100644 --- a/interfaces/kits/js/src/native_devicemanager_js.cpp +++ b/interfaces/kits/js/src/native_devicemanager_js.cpp @@ -623,7 +623,7 @@ std::string DeviceManagerNapi::JsObjectToString(const napi_env &env, const napi_ if (buf == nullptr) { return ""; } - memset_s(buf, (size + 1), 0, (size + 1)); + (void)memset_s(buf, (size + 1), 0, (size + 1)); bool rev = napi_get_value_string_utf8(env, param, buf, size + 1, &size) == napi_ok; std::string value; @@ -769,7 +769,7 @@ void DeviceManagerNapi::JsToDmBuffer(const napi_env &env, const napi_value &obje uint8_t *data = nullptr; napi_get_typedarray_info(env, field, &type, &length, reinterpret_cast(&data), &buffer, &offset); if (type != napi_uint8_array || length == 0 || data == nullptr) { - LOGE("Invaild AppIconInfo"); + LOGE("Invalid AppIconInfo"); return; } *bufferPtr = (uint8_t *)calloc(sizeof(uint8_t), length); diff --git a/services/devicemanagerservice/src/ipc/lite/ipc_server_stub.cpp b/services/devicemanagerservice/src/ipc/lite/ipc_server_stub.cpp index 7e5805940..b06b20650 100644 --- a/services/devicemanagerservice/src/ipc/lite/ipc_server_stub.cpp +++ b/services/devicemanagerservice/src/ipc/lite/ipc_server_stub.cpp @@ -104,14 +104,14 @@ int32_t RegisterDeviceManagerListener(IpcIo *req, IpcIo *reply) LOGE("malloc length invalid!"); return DM_MALLOC_ERROR; } - char *pkgName = (char *)malloc(len + 1); + char *pkgName = new char; if (pkgName == NULL) { LOGE("malloc failed!"); return DM_MALLOC_ERROR; } if (strcpy_s(pkgName, len + 1, (const char *)name) != DM_OK) { LOGE("strcpy_s failed!"); - free(pkgName); + delete pkgName; return DM_COPY_FAILED; } uint32_t cbId = 0; diff --git a/test/unittest/device_manager_impl_test.cpp b/test/unittest/device_manager_impl_test.cpp index 2d26d657f..ead031314 100644 --- a/test/unittest/device_manager_impl_test.cpp +++ b/test/unittest/device_manager_impl_test.cpp @@ -187,6 +187,7 @@ void DeviceDiscoveryCallback::OnDiscoveryFailed(uint16_t subscribeId, int32_t fa void DeviceDiscoveryCallback::OnDeviceFound(uint16_t subscribeId, const DmDeviceInfo &deviceInfo) { (void)subscribeId; + (void)deviceInfo; } } // namespace DistributedHardware } // namespace OHOS diff --git a/test/unittest/mock/device_auth.cpp b/test/unittest/mock/device_auth.cpp index f8d8bfaee..c3076a3d4 100644 --- a/test/unittest/mock/device_auth.cpp +++ b/test/unittest/mock/device_auth.cpp @@ -27,6 +27,10 @@ int32_t (*deleteGroup)(int64_t requestId, const char *appId, const char *disband int32_t (*getRelatedGroups)(const char *appId, const char *peerDeviceId, char **returnGroupVec, uint32_t *groupNum) { + (void)appId; + (void)peerDeviceId; + (void)returnGroupVec; + (void)groupNum; return 0; } @@ -35,6 +39,8 @@ int32_t (*createGroup)(int64_t requestId, const char *appId, const char *createP if (requestId == 0) { return DM_FAILED; } + (void)appId; + (void)createParams; return 0; } @@ -52,4 +58,4 @@ int32_t (*getRelatedGroups)(const char *appId, const char *peerDeviceId, char ** groupNum = 1; returnGroupVec = "123"; } -} \ No newline at end of file +} diff --git a/test/unittest/mock/ipc_server_listener.cpp b/test/unittest/mock/ipc_server_listener.cpp index 6b1395811..0c70d88ae 100644 --- a/test/unittest/mock/ipc_server_listener.cpp +++ b/test/unittest/mock/ipc_server_listener.cpp @@ -18,15 +18,17 @@ namespace OHOS { namespace DistributedHardware { int32_t IpcServerListener::SendRequest(int32_t cmdCode, std::shared_ptr req, std::shared_ptr rsp) { + (void)cmdCode; req_ = req; return 0; } int32_t IpcServerListener::SendAll(int32_t cmdCode, std::shared_ptr req, std::shared_ptr rsp) { + (void)cmdCode; req_ = req; std::cout << req_->GetPkgName() << "\n"; return 0; } } // namespace DistributedHardware -} // namespace OHOS \ No newline at end of file +} // namespace OHOS diff --git a/test/unittest/mock/parameter.cpp b/test/unittest/mock/parameter.cpp index 0b552be58..e2c84304b 100644 --- a/test/unittest/mock/parameter.cpp +++ b/test/unittest/mock/parameter.cpp @@ -17,20 +17,30 @@ int GetParameter(const char *key, const char *def, char *value, unsigned int len) { + (void)key; + (void)def; + (void)value; + (void)len; return 0; } int SetParameter(const char *key, const char *value) { + (void)key; + (void)value; return 0; } int WatchParameter(const char *keyprefix, ParameterChgPtr callback, void *context) { + (void)keyprefix; + (void)context; return 0; } int GetDevUdid(char *udid, int size) { + (void)udid; + (void)size; return 0; -} \ No newline at end of file +} diff --git a/test/unittest/mock/softbus_bus_center.cpp b/test/unittest/mock/softbus_bus_center.cpp index b0ff12f89..6c55bca6e 100644 --- a/test/unittest/mock/softbus_bus_center.cpp +++ b/test/unittest/mock/softbus_bus_center.cpp @@ -18,15 +18,25 @@ int32_t GetNodeKeyInfo(const char *pkgName, const char *networkId, NodeDeviceInfoKey key, uint8_t *info, int32_t infoLen) { + (void)pkgName; + (void)networkId; + (void)key; + (void)info; + (void)infoLen; return 0; } int32_t RegNodeDeviceStateCb(const char *pkgName, INodeStateCb *callback) { + (void)pkgName; + (void)callback; return 0; }; int32_t GetAllNodeDeviceInfo(const char *pkgName, NodeBasicInfo **info, int32_t *infoNum) { + (void)pkgName; + (void)info; + (void)infoNum; return 0; -} \ No newline at end of file +} diff --git a/utils/src/dm_log.cpp b/utils/src/dm_log.cpp index f17b08e8f..898f1afaf 100644 --- a/utils/src/dm_log.cpp +++ b/utils/src/dm_log.cpp @@ -73,9 +73,11 @@ void DmLog(DmLogLevel logLevel, const char *fmt, ...) { char logBuf[LOG_MAX_LEN] = {0}; va_list arg; - int32_t ret = 0; - - (void)memset_s(&arg, sizeof(va_list), 0, sizeof(va_list)); + int32_t ret = memset_s(&arg, sizeof(va_list), 0, sizeof(va_list)); + if (ret != 0) { + DmLogOut(logLevel, "DM log memset_s error."); + return; + } va_start(arg, fmt); ret = vsprintf_s(logBuf, sizeof(logBuf), fmt, arg); va_end(arg); -- Gitee From 6654c82eaf14f3e50aae9d42454ea23e5e9b8a78 Mon Sep 17 00:00:00 2001 From: wangyb0625 Date: Thu, 17 Mar 2022 10:36:32 +0800 Subject: [PATCH 2/5] =?UTF-8?q?=E5=86=85=E6=BA=90=E9=97=AE=E9=A2=98?= =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wangyb0625 --- test/unittest/mock/parameter.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/unittest/mock/parameter.cpp b/test/unittest/mock/parameter.cpp index e2c84304b..d6718efe6 100644 --- a/test/unittest/mock/parameter.cpp +++ b/test/unittest/mock/parameter.cpp @@ -20,7 +20,7 @@ int GetParameter(const char *key, const char *def, char *value, unsigned int len (void)key; (void)def; (void)value; - (void)len; + (void)len; return 0; } -- Gitee From 66686694a0f74661c6ef75ac38a4afaee5174d94 Mon Sep 17 00:00:00 2001 From: wangyb0625 Date: Thu, 17 Mar 2022 18:47:11 +0800 Subject: [PATCH 3/5] =?UTF-8?q?=E5=86=85=E6=BA=90=E9=97=AE=E9=A2=98?= =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wangyb0625 --- .vscode/settings.json | 6 ++++++ OAT.xml | 3 ++- display/entry/build.gradle | 2 +- display/settings.gradle | 16 ++++++++++++++++ .../kits/js/src/native_devicemanager_js.cpp | 8 ++++---- ext/mini/sa_profile/4802.xml | 2 +- .../src/dispatch/command_dispatch.cpp | 4 ++++ .../src/message/msg_request_auth.cpp | 4 ++++ .../src/requestauth/response_session.cpp | 2 +- .../devicemanagerservice/src/timer/dm_timer.cpp | 2 +- ext/mini/utils/src/log/dm_log.cpp | 2 +- .../src/ipc/lite/ipc_client_manager.cpp | 4 ++++ .../src/ipc/standard/ipc_cmd_parser.cpp | 16 ++++++++++++++++ .../src/notify/device_manager_notify.cpp | 4 ++++ .../kits/js/src/native_devicemanager_js.cpp | 6 +++++- .../src/ability/standard/dm_ability_manager.cpp | 2 +- .../src/dependency/hichain/hichain_connector.cpp | 2 +- .../src/dependency/timer/dm_timer.cpp | 1 + .../src/ipc/lite/ipc_cmd_parser.cpp | 8 ++++++++ .../src/ipc/lite/ipc_server_stub.cpp | 6 +++--- .../src/ipc/standard/ipc_server_listener.cpp | 4 ++++ 21 files changed, 88 insertions(+), 16 deletions(-) create mode 100644 .vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 000000000..6c198d185 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,6 @@ +{ + "files.associations": { + "map": "cpp", + "memory": "cpp" + } +} \ No newline at end of file diff --git a/OAT.xml b/OAT.xml index 54fc1b978..43ffcf501 100644 --- a/OAT.xml +++ b/OAT.xml @@ -12,7 +12,8 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. - + --> + diff --git a/display/entry/build.gradle b/display/entry/build.gradle index 9cdfe117a..127dec406 100644 --- a/display/entry/build.gradle +++ b/display/entry/build.gradle @@ -13,7 +13,7 @@ * limitations under the License. */ - apply plugin: 'com.huawei.ohos.hap' +apply plugin: 'com.huawei.ohos.hap' apply plugin: 'com.huawei.ohos.decctest' //For instructions on signature configuration, see https://developer.harmonyos.com/cn/docs/documentation/doc-guides/ide_debug_device-0000001053822404#section1112183053510 ohos { diff --git a/display/settings.gradle b/display/settings.gradle index 4773db732..585467a7a 100644 --- a/display/settings.gradle +++ b/display/settings.gradle @@ -1 +1,17 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + // Top-level build file where you can add configuration options common to all sub-projects/modules. include ':entry' diff --git a/ext/mini/interfaces_mini/kits/js/src/native_devicemanager_js.cpp b/ext/mini/interfaces_mini/kits/js/src/native_devicemanager_js.cpp index 21294ccd0..711d56fe2 100644 --- a/ext/mini/interfaces_mini/kits/js/src/native_devicemanager_js.cpp +++ b/ext/mini/interfaces_mini/kits/js/src/native_devicemanager_js.cpp @@ -818,7 +818,7 @@ JSIValue DeviceManagerModule::StartDeviceDiscoverSync(const JSIValue thisVal, co } if (!JSI::ValueIsObject(args[0])){ - DMLOG(DM_LOG_ERROR, "a object is required."); + DMLOG(DM_LOG_ERROR, "an object is required."); return JSI::CreateNull(); } @@ -895,12 +895,12 @@ JSIValue DeviceManagerModule::AuthenticateDevice(const JSIValue thisVal, const J } if (!JSI::ValueIsObject(args[0])){ - DMLOG(DM_LOG_ERROR, "a object is required."); + DMLOG(DM_LOG_ERROR, "an object is required."); return JSI::CreateNull(); } if (!JSI::ValueIsObject(args[1])){ - DMLOG(DM_LOG_ERROR, "a object is required."); + DMLOG(DM_LOG_ERROR, "an object is required."); return JSI::CreateNull(); } @@ -948,7 +948,7 @@ JSIValue DeviceManagerModule::VerifyAuthInfo(const JSIValue thisVal, const JSIVa } if (!JSI::ValueIsObject(args[0])){ - DMLOG(DM_LOG_ERROR, "a object is required."); + DMLOG(DM_LOG_ERROR, "an object is required."); return JSI::CreateNull(); } diff --git a/ext/mini/sa_profile/4802.xml b/ext/mini/sa_profile/4802.xml index 8d2da2ed9..340088239 100644 --- a/ext/mini/sa_profile/4802.xml +++ b/ext/mini/sa_profile/4802.xml @@ -15,7 +15,7 @@ --> foundation - + 4802 libdevicemanagerservice.z.so diff --git a/ext/mini/services/devicemanagerservice/src/dispatch/command_dispatch.cpp b/ext/mini/services/devicemanagerservice/src/dispatch/command_dispatch.cpp index 76f49d57f..828e62dea 100644 --- a/ext/mini/services/devicemanagerservice/src/dispatch/command_dispatch.cpp +++ b/ext/mini/services/devicemanagerservice/src/dispatch/command_dispatch.cpp @@ -63,6 +63,10 @@ int32_t CommandDispatch::CmdProcessing(int32_t cmdCode, std::shared_ptrSetErrCode(ret); break; } diff --git a/ext/mini/services/devicemanagerservice/src/message/msg_request_auth.cpp b/ext/mini/services/devicemanagerservice/src/message/msg_request_auth.cpp index b4c76bdad..c6ca42340 100644 --- a/ext/mini/services/devicemanagerservice/src/message/msg_request_auth.cpp +++ b/ext/mini/services/devicemanagerservice/src/message/msg_request_auth.cpp @@ -352,6 +352,10 @@ void MsgRequestAuth::SetAuthType(nlohmann::json &json, std::shared_ptrmAuthType_ = authType; } diff --git a/ext/mini/services/devicemanagerservice/src/requestauth/response_session.cpp b/ext/mini/services/devicemanagerservice/src/requestauth/response_session.cpp index 2334fe0b1..f90902686 100644 --- a/ext/mini/services/devicemanagerservice/src/requestauth/response_session.cpp +++ b/ext/mini/services/devicemanagerservice/src/requestauth/response_session.cpp @@ -99,7 +99,7 @@ void ResponseSession::OnUserOperate(int32_t action) break; } case FaAction::USER_OPERATION_TYPE_CANCEL_PINCODE_DISPLAY: { - DMLOG(DM_LOG_ERROR, "cancle pincode display"); + DMLOG(DM_LOG_ERROR, "cancel pincode display"); Release(); break; } diff --git a/ext/mini/services/devicemanagerservice/src/timer/dm_timer.cpp b/ext/mini/services/devicemanagerservice/src/timer/dm_timer.cpp index c455824c5..e899e3580 100644 --- a/ext/mini/services/devicemanagerservice/src/timer/dm_timer.cpp +++ b/ext/mini/services/devicemanagerservice/src/timer/dm_timer.cpp @@ -34,7 +34,7 @@ DmTimer::DmTimer(std::string &name) DmTimer::~DmTimer() { - DMLOG(DM_LOG_INFO, "DmTimer %s Destory in", mTimerName_.c_str()); + DMLOG(DM_LOG_INFO, "DmTimer %s Destroy in", mTimerName_.c_str()); Release(); } diff --git a/ext/mini/utils/src/log/dm_log.cpp b/ext/mini/utils/src/log/dm_log.cpp index 202c20641..491c37244 100644 --- a/ext/mini/utils/src/log/dm_log.cpp +++ b/ext/mini/utils/src/log/dm_log.cpp @@ -74,7 +74,7 @@ void DMLog(DMLogLevel logLevel, const char *fmt, ...) char logBuf[LOG_MAX_LEN] = {0}; va_list arg; - int32_t ret = (void)memset_s(&arg, sizeof(va_list), 0, sizeof(va_list)); + int32_t ret = memset_s(&arg, sizeof(va_list), 0, sizeof(va_list)); if (ret != 0) { DMLogOut(logLevel, "DM log memset_s error."); return; diff --git a/interfaces/inner_kits/native_cpp/src/ipc/lite/ipc_client_manager.cpp b/interfaces/inner_kits/native_cpp/src/ipc/lite/ipc_client_manager.cpp index 4a92a1090..3b89b67f4 100644 --- a/interfaces/inner_kits/native_cpp/src/ipc/lite/ipc_client_manager.cpp +++ b/interfaces/inner_kits/native_cpp/src/ipc/lite/ipc_client_manager.cpp @@ -63,6 +63,10 @@ int32_t IpcClientManager::UnInit(const std::string &pkgName) } std::shared_ptr req = std::make_shared(); std::shared_ptr rsp = std::make_shared(); + if (req == nullptr) { + LOGE("req is null"); + return DM_FAILED; + } req->SetPkgName(pkgName); int32_t ret = serverProxy_.SendCmd(UNREGISTER_DEVICE_MANAGER_LISTENER, req, rsp); if (ret != DM_OK) { diff --git a/interfaces/inner_kits/native_cpp/src/ipc/standard/ipc_cmd_parser.cpp b/interfaces/inner_kits/native_cpp/src/ipc/standard/ipc_cmd_parser.cpp index 984e12af1..3cb76e362 100644 --- a/interfaces/inner_kits/native_cpp/src/ipc/standard/ipc_cmd_parser.cpp +++ b/interfaces/inner_kits/native_cpp/src/ipc/standard/ipc_cmd_parser.cpp @@ -57,6 +57,10 @@ ON_IPC_SET_REQUEST(REGISTER_DEVICE_MANAGER_LISTENER, std::shared_ptr pBa ON_IPC_READ_RESPONSE(REGISTER_DEVICE_MANAGER_LISTENER, MessageParcel &reply, std::shared_ptr pBaseRsp) { + if (pBaseRsp == nullptr) { + LOGE("pBaseRsp is null"); + return DM_FAILED; + } pBaseRsp->SetErrCode(reply.ReadInt32()); return DM_OK; } @@ -105,6 +109,10 @@ ON_IPC_READ_RESPONSE(GET_TRUST_DEVICE_LIST, MessageParcel &reply, std::shared_pt pDmDeviceinfo = (DmDeviceInfo *)reply.ReadRawData(sizeof(DmDeviceInfo)); if (pDmDeviceinfo == nullptr) { LOGE("GetTrustedDeviceList read node info failed!"); + if (pRsp == nullptr) { + LOGE("pRsp is null"); + return DM_FAILED; + } pRsp->SetErrCode(DM_IPC_TRANSACTION_FAILED); return DM_IPC_TRANSACTION_FAILED; } @@ -221,6 +229,10 @@ ON_IPC_SET_REQUEST(STOP_DEVICE_DISCOVER, std::shared_ptr pBaseReq, Messa ON_IPC_READ_RESPONSE(STOP_DEVICE_DISCOVER, MessageParcel &reply, std::shared_ptr pBaseRsp) { + if (pBaseRsp == nullptr) { + LOGE("pBaseRsp is null"); + return DM_FAILED; + } pBaseRsp->SetErrCode(reply.ReadInt32()); return DM_OK; } @@ -255,6 +267,10 @@ ON_IPC_SET_REQUEST(AUTHENTICATE_DEVICE, std::shared_ptr pBaseReq, Messag ON_IPC_READ_RESPONSE(AUTHENTICATE_DEVICE, MessageParcel &reply, std::shared_ptr pBaseRsp) { + if (pBaseRsp == nullptr) { + LOGE("pBaseRsp is null"); + return DM_FAILED; + } pBaseRsp->SetErrCode(reply.ReadInt32()); return DM_OK; } diff --git a/interfaces/inner_kits/native_cpp/src/notify/device_manager_notify.cpp b/interfaces/inner_kits/native_cpp/src/notify/device_manager_notify.cpp index 9eb01d88e..ec0b9827a 100644 --- a/interfaces/inner_kits/native_cpp/src/notify/device_manager_notify.cpp +++ b/interfaces/inner_kits/native_cpp/src/notify/device_manager_notify.cpp @@ -250,6 +250,10 @@ void DeviceManagerNotify::OnAuthResult(const std::string &pkgName, const std::st LOGE("DeviceManager OnAuthResult: no register authCallback for deviceID "); return; } + if(iter->second == nullptr){ + LOGE("DeviceManager OnAuthResult: no register authCallback for OnAuthResult "); + return; + } iter->second->OnAuthResult(deviceId, token, status, (int32_t)reason); authenticateCallback_[pkgName].erase(deviceId); if (authenticateCallback_[pkgName].empty()) { diff --git a/interfaces/kits/js/src/native_devicemanager_js.cpp b/interfaces/kits/js/src/native_devicemanager_js.cpp index 4e1e80c3c..b64820282 100644 --- a/interfaces/kits/js/src/native_devicemanager_js.cpp +++ b/interfaces/kits/js/src/native_devicemanager_js.cpp @@ -623,7 +623,11 @@ std::string DeviceManagerNapi::JsObjectToString(const napi_env &env, const napi_ if (buf == nullptr) { return ""; } - (void)memset_s(buf, (size + 1), 0, (size + 1)); + int32_t ret = memset_s(buf, (size + 1), 0, (size + 1)); + if (ret != 0) { + LOGE( "devicemanager memset_s error."); + return ""; + } bool rev = napi_get_value_string_utf8(env, param, buf, size + 1, &size) == napi_ok; std::string value; diff --git a/services/devicemanagerservice/src/ability/standard/dm_ability_manager.cpp b/services/devicemanagerservice/src/ability/standard/dm_ability_manager.cpp index 2059069c6..ee5a18601 100644 --- a/services/devicemanagerservice/src/ability/standard/dm_ability_manager.cpp +++ b/services/devicemanagerservice/src/ability/standard/dm_ability_manager.cpp @@ -50,7 +50,7 @@ AbilityStatus DmAbilityManager::StartAbility(AbilityRole role) AAFwk::AbilityManagerClient::GetInstance()->Connect(); ErrCode result = AAFwk::AbilityManagerClient::GetInstance()->StartAbility(want); if (result != OHOS::ERR_OK) { - LOGE("Start Ability faild"); + LOGE("Start Ability failed"); mStatus_ = AbilityStatus::ABILITY_STATUS_FAILED; return mStatus_; } diff --git a/services/devicemanagerservice/src/dependency/hichain/hichain_connector.cpp b/services/devicemanagerservice/src/dependency/hichain/hichain_connector.cpp index ce60e6b8d..42d84b46c 100644 --- a/services/devicemanagerservice/src/dependency/hichain/hichain_connector.cpp +++ b/services/devicemanagerservice/src/dependency/hichain/hichain_connector.cpp @@ -350,7 +350,7 @@ int32_t HiChainConnector::GetRelatedGroups(std::string deviceId, std::vectorgetRelatedGroups(userId, DM_PKG_NAME.c_str(), deviceId.c_str(), &returnGroups, &groupNum); if (ret != 0) { - LOGE("HiChainConnector::GetRelatedGroups faild , ret: %d.", ret); + LOGE("HiChainConnector::GetRelatedGroups failed , ret: %d.", ret); return DM_FAILED; } if (returnGroups == nullptr) { diff --git a/services/devicemanagerservice/src/dependency/timer/dm_timer.cpp b/services/devicemanagerservice/src/dependency/timer/dm_timer.cpp index 10f956333..7ac2eb025 100644 --- a/services/devicemanagerservice/src/dependency/timer/dm_timer.cpp +++ b/services/devicemanagerservice/src/dependency/timer/dm_timer.cpp @@ -24,6 +24,7 @@ namespace DistributedHardware { namespace { const int32_t MILL_SECONDS_PER_SECOND = 1000; } + DmTimer::DmTimer(const std::string &name) { if (name.empty()) { diff --git a/services/devicemanagerservice/src/ipc/lite/ipc_cmd_parser.cpp b/services/devicemanagerservice/src/ipc/lite/ipc_cmd_parser.cpp index b390d80f0..d8b4e62e7 100644 --- a/services/devicemanagerservice/src/ipc/lite/ipc_cmd_parser.cpp +++ b/services/devicemanagerservice/src/ipc/lite/ipc_cmd_parser.cpp @@ -44,6 +44,10 @@ ON_IPC_SET_REQUEST(SERVER_DEVICE_STATE_NOTIFY, std::shared_ptr pBaseReq, ON_IPC_READ_RESPONSE(SERVER_DEVICE_STATE_NOTIFY, IpcIo &reply, std::shared_ptr pBaseRsp) { + if (pBaseRsp == nullptr) { + LOGE("pBaseRsp is null"); + return DM_FAILED; + } pBaseRsp->SetErrCode(IpcIoPopInt32(&reply)); return DM_OK; } @@ -65,6 +69,10 @@ ON_IPC_SET_REQUEST(SERVER_DEVICE_FOUND, std::shared_ptr pBaseReq, IpcIo ON_IPC_READ_RESPONSE(SERVER_DEVICE_FOUND, IpcIo &reply, std::shared_ptr pBaseRsp) { + if (pBaseRsp == nullptr) { + LOGE("pBaseRsp is null"); + return DM_FAILED; + } pBaseRsp->SetErrCode(IpcIoPopInt32(&reply)); return DM_OK; } diff --git a/services/devicemanagerservice/src/ipc/lite/ipc_server_stub.cpp b/services/devicemanagerservice/src/ipc/lite/ipc_server_stub.cpp index b06b20650..9bb72de1a 100644 --- a/services/devicemanagerservice/src/ipc/lite/ipc_server_stub.cpp +++ b/services/devicemanagerservice/src/ipc/lite/ipc_server_stub.cpp @@ -104,14 +104,14 @@ int32_t RegisterDeviceManagerListener(IpcIo *req, IpcIo *reply) LOGE("malloc length invalid!"); return DM_MALLOC_ERROR; } - char *pkgName = new char; - if (pkgName == NULL) { + char *pkgName = new char[len+1]; + if (pkgName == nullptr) { LOGE("malloc failed!"); return DM_MALLOC_ERROR; } if (strcpy_s(pkgName, len + 1, (const char *)name) != DM_OK) { LOGE("strcpy_s failed!"); - delete pkgName; + delete[] pkgName; return DM_COPY_FAILED; } uint32_t cbId = 0; diff --git a/services/devicemanagerservice/src/ipc/standard/ipc_server_listener.cpp b/services/devicemanagerservice/src/ipc/standard/ipc_server_listener.cpp index efb4c71b9..81dcc2399 100644 --- a/services/devicemanagerservice/src/ipc/standard/ipc_server_listener.cpp +++ b/services/devicemanagerservice/src/ipc/standard/ipc_server_listener.cpp @@ -40,6 +40,10 @@ int32_t IpcServerListener::SendAll(int32_t cmdCode, std::shared_ptr req, auto remote = iter.second; req->SetPkgName(pkgName); sptr listener = iface_cast(remote); + if (listener == nullptr) { + LOGI("cannot get listener for package:%s.", pkgName.c_str()); + return DM_FAILED; + } listener->SendCmd(cmdCode, req, rsp); } return DM_OK; -- Gitee From a85df7c330efeb788f1c9bab061474360472148b Mon Sep 17 00:00:00 2001 From: wangyb0625 Date: Thu, 17 Mar 2022 18:59:31 +0800 Subject: [PATCH 4/5] =?UTF-8?q?=E5=86=85=E6=BA=90=E9=97=AE=E9=A2=98?= =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wangyb0625 --- .../inner_kits/native_cpp/src/notify/device_manager_notify.cpp | 2 +- interfaces/kits/js/src/native_devicemanager_js.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/interfaces/inner_kits/native_cpp/src/notify/device_manager_notify.cpp b/interfaces/inner_kits/native_cpp/src/notify/device_manager_notify.cpp index ec0b9827a..5081c63b5 100644 --- a/interfaces/inner_kits/native_cpp/src/notify/device_manager_notify.cpp +++ b/interfaces/inner_kits/native_cpp/src/notify/device_manager_notify.cpp @@ -250,7 +250,7 @@ void DeviceManagerNotify::OnAuthResult(const std::string &pkgName, const std::st LOGE("DeviceManager OnAuthResult: no register authCallback for deviceID "); return; } - if(iter->second == nullptr){ + if (iter->second == nullptr) { LOGE("DeviceManager OnAuthResult: no register authCallback for OnAuthResult "); return; } diff --git a/interfaces/kits/js/src/native_devicemanager_js.cpp b/interfaces/kits/js/src/native_devicemanager_js.cpp index b64820282..143805842 100644 --- a/interfaces/kits/js/src/native_devicemanager_js.cpp +++ b/interfaces/kits/js/src/native_devicemanager_js.cpp @@ -625,7 +625,7 @@ std::string DeviceManagerNapi::JsObjectToString(const napi_env &env, const napi_ } int32_t ret = memset_s(buf, (size + 1), 0, (size + 1)); if (ret != 0) { - LOGE( "devicemanager memset_s error."); + LOGE("devicemanager memset_s error."); return ""; } bool rev = napi_get_value_string_utf8(env, param, buf, size + 1, &size) == napi_ok; -- Gitee From 3511bb7387abf3e4a3c121c45dc1010b884da0be Mon Sep 17 00:00:00 2001 From: wangyb0625 Date: Thu, 17 Mar 2022 19:56:15 +0800 Subject: [PATCH 5/5] =?UTF-8?q?=E5=86=85=E6=BA=90=E9=97=AE=E9=A2=98?= =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wangyb0625 --- .../devicemanagerservice/src/dispatch/command_dispatch.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ext/mini/services/devicemanagerservice/src/dispatch/command_dispatch.cpp b/ext/mini/services/devicemanagerservice/src/dispatch/command_dispatch.cpp index 828e62dea..01e8a1c51 100644 --- a/ext/mini/services/devicemanagerservice/src/dispatch/command_dispatch.cpp +++ b/ext/mini/services/devicemanagerservice/src/dispatch/command_dispatch.cpp @@ -66,7 +66,7 @@ int32_t CommandDispatch::CmdProcessing(int32_t cmdCode, std::shared_ptrSetErrCode(ret); break; } -- Gitee