From f52b233d32248f89103cfb2a2d4d6af662d088f5 Mon Sep 17 00:00:00 2001 From: gaobo Date: Mon, 26 Sep 2022 05:32:12 -0700 Subject: [PATCH 1/2] bugfix Signed-off-by: gaobo --- .../cert_manager_standard/main/common/include/cm_type.h | 2 +- interfaces/kits/napi/src/cm_napi_install_app_cert.cpp | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/frameworks/cert_manager_standard/main/common/include/cm_type.h b/frameworks/cert_manager_standard/main/common/include/cm_type.h index 43bce8b..bcc3346 100644 --- a/frameworks/cert_manager_standard/main/common/include/cm_type.h +++ b/frameworks/cert_manager_standard/main/common/include/cm_type.h @@ -37,7 +37,7 @@ extern "C" { #define MAX_LEN_CERTIFICATE_CHAIN (3 * MAX_LEN_CERTIFICATE) -#define MAX_SUFFIX_LEN 8 +#define MAX_SUFFIX_LEN 16 #define MAX_COUNT_CERTIFICATE 256 #define MAX_LEN_URI 64 #define MAX_LEN_CERT_ALIAS 64 diff --git a/interfaces/kits/napi/src/cm_napi_install_app_cert.cpp b/interfaces/kits/napi/src/cm_napi_install_app_cert.cpp index 28db760..5158837 100644 --- a/interfaces/kits/napi/src/cm_napi_install_app_cert.cpp +++ b/interfaces/kits/napi/src/cm_napi_install_app_cert.cpp @@ -134,15 +134,17 @@ static napi_value InstallAppCertParseParams( return GetInt32(env, 0); } -static void InitKeyUri(struct CmBlob *keyUri) +static void InitKeyUri(struct CmBlob *&keyUri) { - if (keyUri == nullptr) { + keyUri = (uint8_t *)CmMalloc(sizeof(struct CmBlob)); + if (keyUri == NULL) { + CM_LOG_E("malloc keyUri buffer failed"); return; } keyUri->data = (uint8_t *)CmMalloc(MAX_LEN_URI); if (keyUri->data == NULL) { - CM_LOG_E("malloc file buffer failed"); + CM_LOG_E("malloc keyUri->data buffer failed"); return; } -- Gitee From ba702f1037d2db29a0c5b999c9bb226c27c9638e Mon Sep 17 00:00:00 2001 From: gaobo Date: Mon, 26 Sep 2022 05:32:12 -0700 Subject: [PATCH 2/2] bugfix --- .../main/common/include/cm_type.h | 2 +- .../os_dependency/cm_ipc/src/cm_ipc_client.c | 19 +++++++++++++++++-- .../napi/src/cm_napi_install_app_cert.cpp | 8 +++++--- .../main/core/src/cert_manager.c | 5 +++-- 4 files changed, 26 insertions(+), 8 deletions(-) diff --git a/frameworks/cert_manager_standard/main/common/include/cm_type.h b/frameworks/cert_manager_standard/main/common/include/cm_type.h index 43bce8b..bcc3346 100644 --- a/frameworks/cert_manager_standard/main/common/include/cm_type.h +++ b/frameworks/cert_manager_standard/main/common/include/cm_type.h @@ -37,7 +37,7 @@ extern "C" { #define MAX_LEN_CERTIFICATE_CHAIN (3 * MAX_LEN_CERTIFICATE) -#define MAX_SUFFIX_LEN 8 +#define MAX_SUFFIX_LEN 16 #define MAX_COUNT_CERTIFICATE 256 #define MAX_LEN_URI 64 #define MAX_LEN_CERT_ALIAS 64 diff --git a/frameworks/cert_manager_standard/main/os_dependency/cm_ipc/src/cm_ipc_client.c b/frameworks/cert_manager_standard/main/os_dependency/cm_ipc/src/cm_ipc_client.c index 5cf152c..829e473 100644 --- a/frameworks/cert_manager_standard/main/os_dependency/cm_ipc/src/cm_ipc_client.c +++ b/frameworks/cert_manager_standard/main/os_dependency/cm_ipc/src/cm_ipc_client.c @@ -256,17 +256,24 @@ int32_t CmClientSetCertStatus(const struct CmContext *cmContext, const struct Cm static int32_t CmInstallAppCertUnpackFromService(const struct CmBlob *outData, struct CmBlob *keyUri) { uint32_t offset = 0; + struct CmBlob blob = { 0, NULL }; + if ((outData == NULL) || (keyUri == NULL) || (outData->data == NULL) || (keyUri->data == NULL)) { return CMR_ERROR_NULL_POINTER; } - int32_t ret = CmGetBlobFromBuffer(keyUri, outData, &offset); + int32_t ret = CmGetBlobFromBuffer(&blob, outData, &offset); if (ret != CM_SUCCESS) { CM_LOG_E("Get keyUri failed"); return ret; } + if ((blob.size > keyUri->size) || memcpy_s(keyUri->data, keyUri->size, blob.data, blob.size) != EOK) { + CM_LOG_E("copy keyUri failed"); + return CMR_ERROR_INVALID_OPERATION; + } + return CM_SUCCESS; } @@ -568,6 +575,8 @@ static int32_t CmGetAppCertFromBuffer(struct Credential *certificateInfo, static int32_t CmAppCertInfoUnpackFromService(const struct CmBlob *outData, struct Credential *certificateInfo) { uint32_t offset = 0; + struct CmBlob blob = { 0, NULL }; + if ((outData == NULL) || (certificateInfo == NULL) || (outData->data == NULL) || (certificateInfo->credData.data == NULL)) { return CMR_ERROR_NULL_POINTER; @@ -597,12 +606,18 @@ static int32_t CmAppCertInfoUnpackFromService(const struct CmBlob *outData, stru return ret; } - ret = CmGetBlobFromBuffer(&certificateInfo->credData, outData, &offset); + ret = CmGetBlobFromBuffer(&blob, outData, &offset); if (ret != CM_SUCCESS) { CM_LOG_E("Get certificateInfo->credData failed"); return ret; } + if ((blob.size > certificateInfo->credData.size) || memcpy_s(certificateInfo->credData.data, + certificateInfo->credData.size, blob.data, blob.size) != EOK) { + CM_LOG_E("copy credData failed"); + return CMR_ERROR_INVALID_OPERATION; + } + return CM_SUCCESS; } diff --git a/interfaces/kits/napi/src/cm_napi_install_app_cert.cpp b/interfaces/kits/napi/src/cm_napi_install_app_cert.cpp index 28db760..5158837 100644 --- a/interfaces/kits/napi/src/cm_napi_install_app_cert.cpp +++ b/interfaces/kits/napi/src/cm_napi_install_app_cert.cpp @@ -134,15 +134,17 @@ static napi_value InstallAppCertParseParams( return GetInt32(env, 0); } -static void InitKeyUri(struct CmBlob *keyUri) +static void InitKeyUri(struct CmBlob *&keyUri) { - if (keyUri == nullptr) { + keyUri = (uint8_t *)CmMalloc(sizeof(struct CmBlob)); + if (keyUri == NULL) { + CM_LOG_E("malloc keyUri buffer failed"); return; } keyUri->data = (uint8_t *)CmMalloc(MAX_LEN_URI); if (keyUri->data == NULL) { - CM_LOG_E("malloc file buffer failed"); + CM_LOG_E("malloc keyUri->data buffer failed"); return; } diff --git a/services/cert_manager_standard/cert_manager_engine/main/core/src/cert_manager.c b/services/cert_manager_standard/cert_manager_engine/main/core/src/cert_manager.c index 3ba5b1c..f667580 100644 --- a/services/cert_manager_standard/cert_manager_engine/main/core/src/cert_manager.c +++ b/services/cert_manager_standard/cert_manager_engine/main/core/src/cert_manager.c @@ -113,13 +113,13 @@ int32_t GetFilePath(const struct CmContext *context, uint32_t store, char *pathP { int32_t ret, retVal; if (suffix == NULL || suffixLen == NULL) { - CM_LOG_E("NULL pointer failure.\n"); + CM_LOG_E("NULL pointer failure"); return CMR_ERROR_NULL_POINTER; } switch (store) { if (context == NULL) { - CM_LOG_E("Null pointer failture.\n"); + CM_LOG_E("Null pointer failture"); return CMR_ERROR_NULL_POINTER; } case CM_CREDENTIAL_STORE: @@ -135,6 +135,7 @@ int32_t GetFilePath(const struct CmContext *context, uint32_t store, char *pathP retVal = sprintf_s(suffix, MAX_SUFFIX_LEN, "%u", context->uid); if (ret < 0 || retVal < 0) { + CM_LOG_E("Construct file Path failed ret:%d, retVal:%d", ret, retVal); return CMR_ERROR; } break; -- Gitee