From 6a5a0326d2b18ffacce5d38fb351530973c2f245 Mon Sep 17 00:00:00 2001 From: pcwlno1 Date: Wed, 4 Aug 2021 08:27:53 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20LiteOS=5FA=20BBOX=20Codex=E6=95=B4?= =?UTF-8?q?=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1、判断安全函数的返回值。 Close #I43RQU Signed-off-by: pcwlno1 --- kernel/common/blackbox/los_blackbox_common.c | 12 ++++++++---- kernel/common/blackbox/los_blackbox_core.c | 20 +++++++++++++++----- 2 files changed, 23 insertions(+), 9 deletions(-) diff --git a/kernel/common/blackbox/los_blackbox_common.c b/kernel/common/blackbox/los_blackbox_common.c index 71be24d0..18cc1d2f 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 0445449e..bf5e74de 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); -- GitLab