mirror of
https://github.com/projectacrn/acrn-hypervisor.git
synced 2025-09-18 23:40:11 +00:00
dm: remove unsafe apis in dm log
sprintf/vsnprintf are not safe, so use snprintf instead of sprintf, use vasprintf instead of vsnprintf. Tracked-On: #3394 Signed-off-by: Tianhua Sun <tianhuax.s.sun@intel.com> Reviewed-by: Yonghua Huang <yonghua.huang@intel.com> Reviewed-by: Minggui Cao <minggui.cao@intel.com>
This commit is contained in:
committed by
ACRN System Integration
parent
d8b752c4ee
commit
e749ced4a0
@@ -69,17 +69,21 @@ static void deinit_kmsg(void)
|
||||
|
||||
static void write_to_kmsg(const char *fmt, va_list args)
|
||||
{
|
||||
char *buf;
|
||||
char kmsg_buf[KMSG_MAX_LEN] = KMSG_PREFIX;
|
||||
int len1, len2;
|
||||
int write_cnt;
|
||||
int len, write_cnt;
|
||||
|
||||
if (kmsg_fd < 0)
|
||||
return;
|
||||
|
||||
len1 = strlen(KMSG_PREFIX);
|
||||
len2 = vsnprintf(kmsg_buf + len1, MAX_ONE_LOG_SIZE, fmt, args);
|
||||
len = vasprintf(&buf, fmt, args);
|
||||
if (len < 0)
|
||||
return;
|
||||
strncpy(kmsg_buf + strlen(KMSG_PREFIX), buf, KMSG_MAX_LEN - strlen(KMSG_PREFIX));
|
||||
kmsg_buf[KMSG_MAX_LEN - 1] = '\0';
|
||||
free(buf);
|
||||
|
||||
write_cnt = write(kmsg_fd, kmsg_buf, len1 + len2);
|
||||
write_cnt = write(kmsg_fd, kmsg_buf, strnlen(kmsg_buf, KMSG_MAX_LEN));
|
||||
if (write_cnt < 0) {
|
||||
perror(KMSG_PREFIX"write kmsg failed");
|
||||
close(kmsg_fd);
|
||||
|
Reference in New Issue
Block a user