m68k: Use strscpy to replace strlcpy
PATCH 1/1 m68k: Use strscpy to replace strlcpy
The strlcpy should not be used because it doesn't limit the source length. Preferred is strscpy.
--- arch/m68k/emu/natfeat.c | 2 +- arch/m68k/kernel/setup_mm.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
arch/m68k/emu/natfeat.c +1 -1
@@ -43,7 +43,7 @@ long nf_get_id(const char *feature_name)char name_copy[32 ];size_t n; - n =strlcpy (name_copy, feature_name,sizeof (name_copy)); + n =strscpy (name_copy, feature_name,sizeof (name_copy));if (n >=sizeof (name_copy))return 0 ;
arch/m68k/kernel/setup_mm.c +1 -1
@@ -158,7 +158,7 @@ static void __init m68k_parse_bootinfo(const struct bi_record *record)break ;case BI_COMMAND_LINE : -strlcpy (m68k_command_line, data, +strscpy (m68k_command_line, data,sizeof (m68k_command_line));break ;
Signature · 1 line
2.36.1
Geert Uytterhoeven
maintainerHi Xuebing,
Quoted 4 lines · 陈学兵
The strlcpy should not be used because it doesn't limit the source length. Preferred is strscpy.
Signed-off-by XueBing Chen <[email protected]>
Thanks for your patch!
arch/m68k/emu/natfeat.c long nf_get_id(const char *feature_name) · line 47
Quoted 9 lines
arch/m68k/emu/natfeat.c +1
-1@@ -43,7 +43,7 @@ long nf_get_id(const char *feature_name)char name_copy[32 ];size_t n; - n =strlcpy (name_copy, feature_name,sizeof (name_copy)); + n =strscpy (name_copy, feature_name,sizeof (name_copy));if (n >=sizeof (name_copy))
You forgot to update the error checking: on failure, strscpy() returns a negative error code. This is assigned to (unsigned) size_t, hence will be larger than sizeof(name_copy). So the check will still still work, but it is non-obvious.
arch/m68k/emu/natfeat.c long nf_get_id(const char *feature_name) · line 49
Quoted 2 lines
arch/m68k/emu/natfeat.c +0
-0return 0 ;
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]
In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds