tools: acrn-crashlog: fix potential buffer overflow issues

This patch is to fix the potential buffer overflow issues.

Signed-off-by: CHEN Gang <gang.c.chen@intel.com>
Reviewed-by: Zhi Jin <zhi.jin@intel.com>
Reviewed-by: xiaojin2 <xiaojing.liu@intel.com>
This commit is contained in:
CHEN Gang
2018-07-06 11:09:46 +08:00
committed by wenlingz
parent 0f6ff87835
commit 6494708f2f
2 changed files with 7 additions and 3 deletions

View File

@@ -17,7 +17,9 @@ void do_log(const int level,
va_list args;
char *fmt;
char log[MAX_LOG_LEN];
char *msg_log;
int n = 0;
int msg_len = 0;
#ifdef DEBUG_ACRN_CRASHLOG
const char header_fmt[] = "<%-20s%5d>: ";
#endif
@@ -40,8 +42,10 @@ void do_log(const int level,
if (n < 0 || (size_t)n >= sizeof(log))
n = 0;
#endif
msg_log = log + n;
msg_len = sizeof(log) - n;
/* msg */
vsnprintf(log + n, sizeof(log) - n, fmt, args);
vsnprintf(msg_log, msg_len, fmt, args);
log[sizeof(log) - 1] = 0;
va_end(args);