From 6e7afc027f004136085c56d523bb1c19163463f1 Mon Sep 17 00:00:00 2001 From: shenchenkai Date: Mon, 6 Dec 2021 17:44:02 +0800 Subject: [PATCH] Description:[fix] fix memory out of bound problem Change-Id: I60c350262c195e57722a9bd244b57e5d3c6e14b6 Signed-off-by: shenchenkai --- frameworks/mini/hiview_output_log.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/frameworks/mini/hiview_output_log.c b/frameworks/mini/hiview_output_log.c index 560b305..cbaf863 100755 --- a/frameworks/mini/hiview_output_log.c +++ b/frameworks/mini/hiview_output_log.c @@ -384,6 +384,9 @@ static int32 LogCommonFmt(char *outStr, int32 outStrLen, const HiLogCommon *comm min = nowTime.tm_min; sec = nowTime.tm_sec; level = CLEAR_HASH_FLAG(commonContentPtr->level); + if (level < 0 || level >= HILOG_LV_MAX) { + level = 0; + } ret = snprintf_s(outStr, outStrLen, outStrLen - 1, "%02d-%02d %02d:%02d:%02d.%03d 0 %d %c %d/%s: ", month, day, hour, min, sec, commonContentPtr->milli, commonContentPtr->task, g_logLevelInfo[level], commonContentPtr->module, HiLogGetModuleName(commonContentPtr->module)); @@ -448,6 +451,9 @@ static int32 LogDebugValuesFmt(char *desStrPtr, int32 desLen, const HiLogContent switch (logContentPtr->commonContent.valueNumber) { case LOG_MULTI_PARA_0: ret = strncpy_s(desStrPtr, desLen, logContentPtr->commonContent.fmt, desLen - 1); + if (ret != EOK) { + ret = -1; + } break; case LOG_MULTI_PARA_1: ret = snprintf_s(desStrPtr, desLen, desLen - 1, logContentPtr->commonContent.fmt, -- Gitee