Re: [PATCH] Support the nonstring variable attribute (gcc >= 8)

From: David Rientjes
Date: Sun Feb 18 2018 - 18:20:33 EST


On Sat, 17 Feb 2018, Miguel Ojeda wrote:

> From the GCC manual:
>
> The nonstring variable attribute specifies that an object or member
> declaration with type array of char or pointer to char is intended to
> store character arrays that do not necessarily contain a terminating NUL
> character. This is useful in detecting uses of such arrays or pointers
> with functions that expect NUL-terminated strings, and to avoid warnings
> when such an array or pointer is used as an argument to a bounded string
> manipulation function such as strncpy.
>
> https://gcc.gnu.org/onlinedocs/gcc/Common-Variable-Attributes.html
>
> Some reports are already coming to the LKML regarding these
> warnings. When they are false positives, we can use __nonstring to let
> gcc know a NUL character is not required; like in this case:
>
> https://lkml.org/lkml/2018/1/16/135
>
> Signed-off-by: Miguel Ojeda <miguel.ojeda.sandonis@xxxxxxxxx>
> Cc: Ingo Molnar <mingo@xxxxxxxxxx>
> Cc: Josh Poimboeuf <jpoimboe@xxxxxxxxxx>
> Cc: Kees Cook <keescook@xxxxxxxxxxxx>
> Cc: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx>
> Cc: Geert Uytterhoeven <geert@xxxxxxxxxxxxxx>
> Cc: Will Deacon <will.deacon@xxxxxxx>
> Cc: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx>
> Cc: David Rientjes <rientjes@xxxxxxxxxx>

I would have expected to have seen __nonstring used somewhere as part of
this patch.