From 61c1375c1dee8573a2d0e9cb35ba2480f5dc4d8d Mon Sep 17 00:00:00 2001 From: wangyb0625 Date: Thu, 14 Jul 2022 15:17:10 +0800 Subject: [PATCH 1/2] =?UTF-8?q?fuzz=E9=94=99=E8=AF=AF=E6=95=B4=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wangyb0625 --- common/include/dm_constants.h | 3 +++ .../src/authentication/dm_auth_manager.cpp | 13 +++++++++++++ .../src/device_manager_service_impl.cpp | 8 ++++++++ 3 files changed, 24 insertions(+) diff --git a/common/include/dm_constants.h b/common/include/dm_constants.h index 1ef1c554..a62d1295 100755 --- a/common/include/dm_constants.h +++ b/common/include/dm_constants.h @@ -49,6 +49,9 @@ const int32_t DISCOVER_STATUS_LEN = 20; const int32_t COMMON_CALLBACK_MAX_SIZE = 200; const uint32_t MAX_LOAD_VALUE = 3; +const int32_t DM_AUTH_TYPE_MAX = 4; +const int32_t DM_AUTH_TYPE_MIN = 1; + enum { DM_OK = 0, ERR_DM_FAILED = -20000, diff --git a/services/implementation/src/authentication/dm_auth_manager.cpp b/services/implementation/src/authentication/dm_auth_manager.cpp index ce134e4e..835a668e 100644 --- a/services/implementation/src/authentication/dm_auth_manager.cpp +++ b/services/implementation/src/authentication/dm_auth_manager.cpp @@ -61,7 +61,20 @@ int32_t DmAuthManager::AuthenticateDevice(const std::string &pkgName, int32_t au const std::string &extra) { LOGI("DmAuthManager::AuthenticateDevice start auth type %d", authType); + if (authType < DM_AUTH_TYPE_MIN || authType > DM_AUTH_TYPE_MAX) { + LOGE("AuthenticateDevice failed, authType is empty"); + return ERR_DM_INPUT_PARAMETER_EMPTY; + } + if (pkgName.empty() || deviceId.empty() || extra.empty()) { + LOGE("DmAuthManager::AuthenticateDevice failed, pkgName is %s, deviceId is %s, extra is %s", + pkgName.c_str(), deviceId.c_str(), extra.c_str()); + return ERR_DM_INPUT_PARAMETER_EMPTY; + } std::shared_ptr authentication = authenticationMap_[authType]; + if (listener_ == nullptr) { + LOGE("DmAuthManager::AuthenticateDevice is empty nullptr."); + return ERR_DM_AUTH_FAILED; + } if (authentication == nullptr) { LOGE("DmAuthManager::AuthenticateDevice authType %d not support.", authType); listener_->OnAuthResult(pkgName, deviceId, "", AuthState::AUTH_REQUEST_INIT, ERR_DM_UNSUPPORTED_AUTH_TYPE); diff --git a/services/implementation/src/device_manager_service_impl.cpp b/services/implementation/src/device_manager_service_impl.cpp index ad4a5181..50790d13 100644 --- a/services/implementation/src/device_manager_service_impl.cpp +++ b/services/implementation/src/device_manager_service_impl.cpp @@ -167,6 +167,14 @@ int32_t DeviceManagerServiceImpl::AuthenticateDevice(const std::string &pkgName, LOGE("AuthenticateDevice failed, deviceId is empty"); return ERR_DM_INPUT_PARAMETER_EMPTY; } + if (authType < DM_AUTH_TYPE_MIN || authType > DM_AUTH_TYPE_MAX) { + LOGE("AuthenticateDevice failed, authType is empty"); + return ERR_DM_INPUT_PARAMETER_EMPTY; + } + if (extra.empty()) { + LOGE("AuthenticateDevice failed, extra is empty"); + return ERR_DM_INPUT_PARAMETER_EMPTY; + } return authMgr_->AuthenticateDevice(pkgName, authType, deviceId, extra); } From 9c16675865d97bf3f3a5509b668c029dea33da44 Mon Sep 17 00:00:00 2001 From: wangyb0625 Date: Thu, 14 Jul 2022 15:35:23 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E4=BF=AE=E6=94=B9fuzz?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wangyb0625 --- .../implementation/src/authentication/dm_auth_manager.cpp | 8 ++++---- .../implementation/src/device_manager_service_impl.cpp | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/services/implementation/src/authentication/dm_auth_manager.cpp b/services/implementation/src/authentication/dm_auth_manager.cpp index 835a668e..9fe650a0 100644 --- a/services/implementation/src/authentication/dm_auth_manager.cpp +++ b/services/implementation/src/authentication/dm_auth_manager.cpp @@ -62,8 +62,8 @@ int32_t DmAuthManager::AuthenticateDevice(const std::string &pkgName, int32_t au { LOGI("DmAuthManager::AuthenticateDevice start auth type %d", authType); if (authType < DM_AUTH_TYPE_MIN || authType > DM_AUTH_TYPE_MAX) { - LOGE("AuthenticateDevice failed, authType is empty"); - return ERR_DM_INPUT_PARAMETER_EMPTY; + LOGE("AuthenticateDevice failed, authType is illegal"); + return ERR_DM_AUTH_FAILED; } if (pkgName.empty() || deviceId.empty() || extra.empty()) { LOGE("DmAuthManager::AuthenticateDevice failed, pkgName is %s, deviceId is %s, extra is %s", @@ -72,8 +72,8 @@ int32_t DmAuthManager::AuthenticateDevice(const std::string &pkgName, int32_t au } std::shared_ptr authentication = authenticationMap_[authType]; if (listener_ == nullptr) { - LOGE("DmAuthManager::AuthenticateDevice is empty nullptr."); - return ERR_DM_AUTH_FAILED; + LOGE("DmAuthManager::AuthenticateDevice is empty nullptr"); + return ERR_DM_INPUT_PARAMETER_EMPTY; } if (authentication == nullptr) { LOGE("DmAuthManager::AuthenticateDevice authType %d not support.", authType); diff --git a/services/implementation/src/device_manager_service_impl.cpp b/services/implementation/src/device_manager_service_impl.cpp index 50790d13..9a3e7751 100644 --- a/services/implementation/src/device_manager_service_impl.cpp +++ b/services/implementation/src/device_manager_service_impl.cpp @@ -168,8 +168,8 @@ int32_t DeviceManagerServiceImpl::AuthenticateDevice(const std::string &pkgName, return ERR_DM_INPUT_PARAMETER_EMPTY; } if (authType < DM_AUTH_TYPE_MIN || authType > DM_AUTH_TYPE_MAX) { - LOGE("AuthenticateDevice failed, authType is empty"); - return ERR_DM_INPUT_PARAMETER_EMPTY; + LOGE("AuthenticateDevice failed, authType is illegal"); + return ERR_DM_AUTH_FAILED; } if (extra.empty()) { LOGE("AuthenticateDevice failed, extra is empty");