diff --git a/kernel/common/blackbox/los_blackbox_common.c b/kernel/common/blackbox/los_blackbox_common.c index 71be24d04b52b2c0e151515b7836258e4a31d2b2..18cc1d2fcb136009ace64eaa9b2aace719402333 100644 --- a/kernel/common/blackbox/los_blackbox_common.c +++ b/kernel/common/blackbox/los_blackbox_common.c @@ -113,10 +113,14 @@ int SaveBasicErrorInfo(const char *filePath, struct ErrorInfo *info) return -1; } (void)memset_s(buf, ERROR_INFO_MAX_LEN, 0, ERROR_INFO_MAX_LEN); - (void)snprintf_s(buf, ERROR_INFO_MAX_LEN, ERROR_INFO_MAX_LEN - 1, - ERROR_INFO_HEADER_FORMAT, info->event, info->module, info->errorDesc); - *(buf + ERROR_INFO_MAX_LEN - 1) = '\0'; - (void)FullWriteFile(filePath, buf, strlen(buf), 0); + if (snprintf_s(buf, ERROR_INFO_MAX_LEN, ERROR_INFO_MAX_LEN - 1, + ERROR_INFO_HEADER_FORMAT, info->event, info->module, info->errorDesc) != -1) { + *(buf + ERROR_INFO_MAX_LEN - 1) = '\0'; + (void)FullWriteFile(filePath, buf, strlen(buf), 0); + } else { + BBOX_PRINT_ERR("buf is not enough or snprintf_s failed!\n"); + } + (void)LOS_MemFree(m_aucSysMem1, buf); return 0; diff --git a/kernel/common/blackbox/los_blackbox_core.c b/kernel/common/blackbox/los_blackbox_core.c index 0445449ed85164e637ac80e76eed684df9eba7f8..bf5e74de90f52fca0c72b27ec09abd8513788cfa 100644 --- a/kernel/common/blackbox/los_blackbox_core.c +++ b/kernel/common/blackbox/los_blackbox_core.c @@ -80,10 +80,16 @@ static void FormatErrorInfo(struct ErrorInfo *info, } (void)memset_s(info, sizeof(*info), 0, sizeof(*info)); - (void)strncpy_s(info->event, sizeof(info->event), event, Min(strlen(event), sizeof(info->event) - 1)); - (void)strncpy_s(info->module, sizeof(info->module), module, Min(strlen(module), sizeof(info->module) - 1)); - (void)strncpy_s(info->errorDesc, sizeof(info->errorDesc), errorDesc, - Min(strlen(errorDesc), sizeof(info->errorDesc) - 1)); + if (strncpy_s(info->event, sizeof(info->event), event, Min(strlen(event), sizeof(info->event) - 1)) != EOK) { + BBOX_PRINT_ERR("info->event is not enough or strncpy_s failed!\n"); + } + if (strncpy_s(info->module, sizeof(info->module), module, Min(strlen(module), sizeof(info->module) - 1)) != EOK) { + BBOX_PRINT_ERR("info->module is not enough or strncpy_s failed!\n"); + } + if (strncpy_s(info->errorDesc, sizeof(info->errorDesc), errorDesc, + Min(strlen(errorDesc), sizeof(info->errorDesc) - 1)) != EOK) { + BBOX_PRINT_ERR("info->errorDesc is not enough or strncpy_s failed!\n"); + } } #ifdef LOSCFG_FS_VFS @@ -351,7 +357,11 @@ int BBoxRegisterModuleOps(struct ModuleOps *ops) return -1; } (void)memset_s(newOps, sizeof(*newOps), 0, sizeof(*newOps)); - (void)memcpy_s(&newOps->ops, sizeof(newOps->ops), ops, sizeof(*ops)); + if (memcpy_s(&newOps->ops, sizeof(newOps->ops), ops, sizeof(*ops)) != EOK) { + BBOX_PRINT_ERR("newOps->ops is not enough or memcpy_s failed!\n"); + (void)LOS_MemFree(m_aucSysMem1, newOps); + return -1; + } if (LOS_SemPend(g_opsListSem, LOS_WAIT_FOREVER) != LOS_OK) { BBOX_PRINT_ERR("Request g_opsListSem failed!\n"); (void)LOS_MemFree(m_aucSysMem1, newOps);