Re: [PATCH] wifi: mwifiex: Add __nonstring annotations for unterminated strings
From: Brian Norris
Date: Tue Mar 25 2025 - 18:41:56 EST
On Mon, Mar 10, 2025 at 03:23:32PM -0700, Kees Cook wrote:
> When a character array without a terminating NUL character has a static
> initializer, GCC 15's -Wunterminated-string-initialization will only
> warn if the array lacks the "nonstring" attribute[1]. Mark the arrays
> with __nonstring to and correctly identify the char array as "not a C
> string" and thereby eliminate the warning.
>
> Link: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=117178 [1]
> Cc: Brian Norris <briannorris@xxxxxxxxxxxx>
> Cc: Francesco Dolcini <francesco@xxxxxxxxxx>
> Cc: Johannes Berg <johannes@xxxxxxxxxxxxxxxx>
> Cc: Thomas Gleixner <tglx@xxxxxxxxxxxxx>
> Cc: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx>
> Cc: Allison Randal <allison@xxxxxxxxxxx>
> Cc: linux-wireless@xxxxxxxxxxxxxxx
> Signed-off-by: Kees Cook <kees@xxxxxxxxxx>
This code is kinda weird, because only 2 bytes actually end up used, and
yet we explicitly initialize it with 3 non-NUL bytes.
This solutions seems fine though, as it is indeed not a C string and
does not desire nor rely on a NUL byte:
Acked-by: Brian Norris <briannorris@xxxxxxxxxxxx>
Looks like Johannes already applied it anyway.