RE: [PATCH v1 1/1] seq_file: Replace strncpy()+nul by strscpy()

David Laight
2023-07-18T09:42:21Z

From: Andy Shevchenko
> Sent: 17 July 2023 10:34
...
> #define seq_show_option_n(m, name, value, length) { \
> char val_buf[length + 1]; \
> - strncpy(val_buf, value, length); \
> - val_buf[length] = '\0'; \
> + strscpy(val_buf, value, sizeof(val_buf)); \
> seq_show_option(m, name, val_buf); \
> }

Why the extra double-copy with (potentially) a VLA?

seq_show_option() calls seq_escape_str(),
seq_escape_str calls seq_escape_mem(... strlen(src) ...).

Implement seq_show_option() as seq_show_option_n(... strlen(value))
and use seq_escape_mem() for the value.

David

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)