Re: [PATCH] reiserfs: replace deprecated strncpy with scnprintf

From: Kees Cook
Date: Wed Apr 24 2024 - 19:54:50 EST


On Thu, 28 Mar 2024 21:16:52 +0000, Justin Stitt wrote:
> strncpy() is deprecated for use on NUL-terminated destination strings
> [1] and as such we should prefer more robust and less ambiguous string
> interfaces.
>
> Our goal here is to get @namebuf populated with @name's contents but
> surrounded with quotes. There is some careful handling done to ensure we
> properly truncate @name so that we have room for a literal quote as well
> as a NUL-term. All this careful handling can be done with scnprintf
> using the dynamic string width specifier %.*s which allows us to pass in
> the max size for a source string. Doing this, we can put literal quotes
> in our format specifier and ensure @name is truncated to fit inbetween
> these quotes (-3 is from 2 quotes + 1 NUL-byte).
>
> [...]

Applied to for-next/hardening, thanks!

[1/1] reiserfs: replace deprecated strncpy with scnprintf
https://git.kernel.org/kees/c/ba287092ae90

Take care,

--
Kees Cook