ubsan: remove most sprintf calls

sprintf is implemented as snprintf(..., INT_MAX, ...) which will overflow
the argument pointer for the end, then fix the end to be -1.
This technically works but we know the actual buffer size in all these
call sites, might as well do this properly

Change-Id: I807d09f46a0221f539063fda515e1c504e658d40
This commit is contained in:
Dominique Martinet
2018-12-26 15:08:41 +09:00
parent bc2a444828
commit 4bdd9cf512
3 changed files with 28 additions and 16 deletions

View File

@@ -25,7 +25,7 @@
struct ihk_kmsg_buf *kmsg_buf;
extern int vsnprintf(char *buf, size_t size, const char *fmt, va_list args);
extern int sprintf(char * buf, const char *fmt, ...);
extern int snprintf(char *buf, size_t size, const char *fmt, ...);
extern void eventfd(int type);
static ihk_spinlock_t kmsg_lock;
extern char *find_command_line(char *name);
@@ -110,7 +110,8 @@ int __kprintf(const char *format, ...)
}
/* Copy into the local buf */
len = sprintf(buf, "[%3d]: ", ihk_mc_get_processor_id());
len = snprintf(buf, KPRINTF_LOCAL_BUF_LEN, "[%3d]: ",
ihk_mc_get_processor_id());
va_start(va, format);
len += vsnprintf(buf + len, KPRINTF_LOCAL_BUF_LEN - len - 2, format, va);
@@ -149,7 +150,8 @@ int kprintf(const char *format, ...)
}
/* Copy into the local buf */
len = sprintf(buf, "[%3d]: ", ihk_mc_get_processor_id());
len = snprintf(buf, KPRINTF_LOCAL_BUF_LEN, "[%3d]: ",
ihk_mc_get_processor_id());
va_start(va, format);
len += vsnprintf(buf + len, KPRINTF_LOCAL_BUF_LEN - len - 2, format, va);