Skip to content

Commit be8dffa

Browse files
JustinStittkees
authored andcommitted
um: refactor deprecated strncpy to memcpy
Use `memcpy` since `console_buf` is not expected to be NUL-terminated and it more accurately describes what is happening with the buffers `console_buf` and `string` as per Kees' analysis [1]. Also mark char buffer as `__nonstring` as per Kees' suggestion [2]. This change now makes it more clear what this code does and that `console_buf` is not expected to be NUL-terminated. Link: https://lore.kernel.org/all/202308081708.D5ADC80F@keescook/ [1] Link: KSPP/linux#90 [2] Link: https://www.kernel.org/doc/html/latest/process/deprecated.html#strncpy-on-nul-terminated-strings Cc: [email protected] Suggested-by: Kees Cook <[email protected]> Signed-off-by: Justin Stitt <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Kees Cook <[email protected]>
1 parent 30bed99 commit be8dffa

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

arch/um/drivers/mconsole_kern.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -554,7 +554,7 @@ struct mconsole_output {
554554

555555
static DEFINE_SPINLOCK(client_lock);
556556
static LIST_HEAD(clients);
557-
static char console_buf[MCONSOLE_MAX_DATA];
557+
static char console_buf[MCONSOLE_MAX_DATA] __nonstring;
558558

559559
static void console_write(struct console *console, const char *string,
560560
unsigned int len)
@@ -567,7 +567,7 @@ static void console_write(struct console *console, const char *string,
567567

568568
while (len > 0) {
569569
n = min((size_t) len, ARRAY_SIZE(console_buf));
570-
strncpy(console_buf, string, n);
570+
memcpy(console_buf, string, n);
571571
string += n;
572572
len -= n;
573573

0 commit comments

Comments
 (0)