Skip to content

Commit 6494708

Browse files
chengangcwenlingz
authored andcommitted
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>
1 parent 0f6ff87 commit 6494708

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

tools/acrn-crashlog/common/log_sys.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ void do_log(const int level,
1717
va_list args;
1818
char *fmt;
1919
char log[MAX_LOG_LEN];
20+
char *msg_log;
2021
int n = 0;
22+
int msg_len = 0;
2123
#ifdef DEBUG_ACRN_CRASHLOG
2224
const char header_fmt[] = "<%-20s%5d>: ";
2325
#endif
@@ -40,8 +42,10 @@ void do_log(const int level,
4042
if (n < 0 || (size_t)n >= sizeof(log))
4143
n = 0;
4244
#endif
45+
msg_log = log + n;
46+
msg_len = sizeof(log) - n;
4347
/* msg */
44-
vsnprintf(log + n, sizeof(log) - n, fmt, args);
48+
vsnprintf(msg_log, msg_len, fmt, args);
4549
log[sizeof(log) - 1] = 0;
4650
va_end(args);
4751

tools/acrn-crashlog/usercrash/protocol.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ static int socket_make_sockaddr_un(const char *name,
4444
name_len = strlen(name);
4545
if (name_len >= (SUN_PATH_MAX - socket_len))
4646
return -1;
47-
strcat(p_addr->sun_path, name);
47+
strncat(p_addr->sun_path, name, SUN_PATH_MAX - socket_len);
4848

4949
p_addr->sun_family = AF_LOCAL;
5050
*alen = name_len + socket_len +
@@ -111,7 +111,7 @@ static int socket_bind(int fd, const char *name)
111111
name_len = strlen(name);
112112
if (name_len >= SUN_PATH_MAX)
113113
return -1;
114-
strcpy(addr.sun_path, name);
114+
strncpy(addr.sun_path, name, SUN_PATH_MAX);
115115
unlink(addr.sun_path);
116116
alen = strlen(addr.sun_path) + sizeof(addr.sun_family);
117117

0 commit comments

Comments
 (0)