Hi Xuebing, On Mon, May 23, 2022 at 9:09 AM 陈学兵 <chenxuebing@xxxxxxx> wrote:
The strlcpy should not be used because it doesn't limit the source length. Preferred is strscpy. Signed-off-by: XueBing Chen <chenxuebing@xxxxxxx>
Thanks for your patch!
--- a/arch/m68k/emu/natfeat.c +++ b/arch/m68k/emu/natfeat.c @@ -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.
return 0;
Gr{oetje,eeting}s, Geert -- Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@xxxxxxxxxxxxxx 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