ARM: atags_compat: avoid -Warray-bounds warning
PATCH 1/1 ARM: atags_compat: avoid -Warray-bounds warning
From: Arnd Bergmann <[email protected]>
gcc-11 reports a struct member overflow when copying a string into a single-character array:
In file included from arch/arm/kernel/atags_compat.c:17:
In function 'strcpy',
inlined from 'build_tag_list' at arch/arm/kernel/atags_compat.c:200:2:include/linux/string.h:287:29: warning: '__builtin_strcpy' offset 108 from the object at 'taglist' is out of the bounds of referenced subobject 'cmdline' with type 'char[1]' at offset 108 [-Warray-bounds]
287 | #define __underlying_strcpy __builtin_strcpy
| ^include/linux/string.h:481:10: note: in expansion of macro '__underlying_strcpy'
481 | return __underlying_strcpy(p, q);
| ^~~~~~~~~~~~~~~~~~~In file included from arch/arm/include/asm/setup.h:14,
from arch/arm/kernel/atags_compat.c:20:arch/arm/kernel/atags_compat.c: In function 'build_tag_list':arch/arm/include/uapi/asm/setup.h:127:7: note: subobject 'cmdline' declared here
127 | char cmdline[1]; /* this is the minimum size */
| ^~~~~~~
The code is otherwise correct, so just shut up the warning by not letting the compiler see the underlying type.
--- arch/arm/kernel/atags_compat.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm/kernel/atags_compat.c +1 -1
@@ -197,7 +197,7 @@ static void __init build_tag_list(struct param_struct *params, void *taglist) tag->hdr.tag =ATAG_CMDLINE ; tag->hdr.size = (strlen (params->commandline) +3 +sizeof (struct tag_header )) >>2 ; -strcpy (tag->u.cmdline.cmdline, params->commandline); +strcpy ((void *)&tag->u, params->commandline); tag =tag_next (tag); tag->hdr.tag =ATAG_NONE ;
Signature · 1 line
2.27.0