um: refactor deprecated strncpy to strtomem
PATCH v2 1/1 um: refactor deprecated strncpy to strtomem
Favor a more robust and less ambiguous interface over strncpy.
Use strtomem here since console_buf is not expected to be NUL-terminated.
Also mark char buffer as __nonstring as per Kees' suggestion here [1]
---
Changes in v2:
- Keep usage of ARRAY_SIZE (thanks Bill)
- Remove unnecessary import (thanks Kees and Bill)
- Link to v1: https://lore.kernel.org/r/[email protected]
---
Notes:
I only build tested this patch.
I am also making an assumption that console_buf need not be NUL-terminated. Am I right in believing this?
--- arch/um/drivers/mconsole_kern.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
arch/um/drivers/mconsole_kern.c +2 -2
@@ -554,7 +554,7 @@ struct mconsole_output {static DEFINE_SPINLOCK (client_lock);static LIST_HEAD (clients); -static char console_buf[MCONSOLE_MAX_DATA ]; +static char console_buf[MCONSOLE_MAX_DATA] __nonstring;static void console_write (struct console *console,const char *string,unsigned int len)
@@ -567,7 +567,7 @@ static void console_write(struct console *console, const char *string,while (len >0 ) { n =min ((size_t ) len,ARRAY_SIZE (console_buf)); -strncpy (console_buf, string, n); +strtomem (console_buf, string); string += n; len -= n;
---
base-commit: c1a515d3c0270628df8ae5f5118ba859b85464a2
change-id: 20230807-arch-um-3ef24413427e
Best regards,
--
Justin Stitt <[email protected]>
_______________________________________________
linux-um mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-um
Quoted 40 lines · Justin Stitt
Favor a more robust and less ambiguous interface over
strncpy.Use
strtomemhere sinceconsole_bufis not expected to be NUL-terminated.Also mark char buffer as
__nonstringas per Kees' suggestion here [1]Link www.kernel.org/doc/html/latest/process/deprecated.html#strncpy-on-nul-terminated-stringsSigned-off-by Justin Stitt <[email protected]>---
Changes in v2:
- Keep usage ofARRAY_SIZE(thanks Bill)
- Remove unnecessary import (thanks Kees and Bill)
- Link to v1: https://lore.kernel.org/r/[email protected]
---
Notes:
I only build tested this patch.I am also making an assumption that
console_bufneed not be NUL-terminated. Am I right in believing this?--- arch/um/drivers/mconsole_kern.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)arch/um/drivers/mconsole_kern.c +1
-1@@ -554,7 +554,7 @@ struct mconsole_output {static DEFINE_SPINLOCK (client_lock);static LIST_HEAD (clients); -static char console_buf[MCONSOLE_MAX_DATA ]; +static char console_buf[MCONSOLE_MAX_DATA] __nonstring;static void console_write (struct console *console,const char *string,unsigned int len)
arch/um/drivers/mconsole_kern.c static void console_write(struct console *console, const char *string, · line 570
Quoted 5 lines
arch/um/drivers/mconsole_kern.c +1
-1@@ -567,7 +567,7 @@ static void console_write(struct console *console, const char *string,while (len >0 ) { n =min ((size_t ) len,ARRAY_SIZE (console_buf)); -strncpy (console_buf, string, n); +strtomem (console_buf, string);
See my reply to v1: I think this should just be memcpy(console_buf, string, n)
-Kees
Quoted 12 lines
arch/um/drivers/mconsole_kern.c +0
-1string += n; len -= n; ---base-commit:
c1a515d3c0270628df8ae5f5118ba859b85464a2
change-id: 20230807-arch-um-3ef24413427eBest regards,
--
Justin Stitt <[email protected]>
Signature · 1 line
Kees Cook