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 43bce8b394d74bc192c8808794fa16ab0ffb7ded..bcc334684e1c77f0cb9d2250df6a19feebd868b8 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 5cf152c833d22f96005c1f5f9f57a1f7f41b59d3..829e473b262c49160675bd9da4b22448101a0c12 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 28db760f9be192357e5201fc32a3dbfeadf4a806..5158837599364137e497235b876e4aa968c19475 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 3ba5b1cb089d771d6bc915da1d587057f93e4828..f667580b8fcf4e98727fa6ce003488b8e7252c3c 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;