linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] objtool: Fix -Wformat-truncation seen with GCC 12.
@ 2022-01-12  9:29 Martin Liška
  2022-01-12  9:38 ` David Laight
  2022-01-12  9:41 ` Miroslav Benes
  0 siblings, 2 replies; 3+ messages in thread
From: Martin Liška @ 2022-01-12  9:29 UTC (permalink / raw)
  To: linux-kernel

The patch fixes the following warning that seems reasonable:

check.c:2836:58: error: '%d' directive output may be truncated writing between 1 and 10 bytes into a region of size 9 [-Werror=format-truncation=]
2836 |                 snprintf(pvname, sizeof(pvname), "pv_ops[%d]", idx);

Signed-off-by: Martin Liška <mliska@suse.cz>
---
  tools/objtool/check.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/objtool/check.c b/tools/objtool/check.c
index a9a1f7259d62..9555f7ad57cd 100644
--- a/tools/objtool/check.c
+++ b/tools/objtool/check.c
@@ -2852,7 +2852,7 @@ static inline bool func_uaccess_safe(struct symbol *func)
  
  static inline const char *call_dest_name(struct instruction *insn)
  {
-	static char pvname[16];
+	static char pvname[20];
  	struct reloc *rel;
  	int idx;
  
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* RE: [PATCH] objtool: Fix -Wformat-truncation seen with GCC 12.
  2022-01-12  9:29 [PATCH] objtool: Fix -Wformat-truncation seen with GCC 12 Martin Liška
@ 2022-01-12  9:38 ` David Laight
  2022-01-12  9:41 ` Miroslav Benes
  1 sibling, 0 replies; 3+ messages in thread
From: David Laight @ 2022-01-12  9:38 UTC (permalink / raw)
  To: 'Martin Liška', linux-kernel

From: Martin Liška
> Sent: 12 January 2022 09:29
> 
> The patch fixes the following warning that seems reasonable:
> 
> check.c:2836:58: error: '%d' directive output may be truncated writing between 1 and 10 bytes into a
> region of size 9 [-Werror=format-truncation=]
> 2836 |                 snprintf(pvname, sizeof(pvname), "pv_ops[%d]", idx);

Looks pretty unreasonable to me :-)
The domain of 'idx' is much smaller than that of 'int'.
Indeed the overflow can only actually happen if it is negative.
By then all sorts of other things will have gone wrong.

OTOH changing 16 to 60 is one way to STFU.

	David

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

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] objtool: Fix -Wformat-truncation seen with GCC 12.
  2022-01-12  9:29 [PATCH] objtool: Fix -Wformat-truncation seen with GCC 12 Martin Liška
  2022-01-12  9:38 ` David Laight
@ 2022-01-12  9:41 ` Miroslav Benes
  1 sibling, 0 replies; 3+ messages in thread
From: Miroslav Benes @ 2022-01-12  9:41 UTC (permalink / raw)
  To: Martin Liška; +Cc: linux-kernel, peterz, jpoimboe

[-- Attachment #1: Type: text/plain, Size: 1058 bytes --]

Hi,

On Wed, 12 Jan 2022, Martin Liška wrote:

> The patch fixes the following warning that seems reasonable:
> 
> check.c:2836:58: error: '%d' directive output may be truncated writing between
> 1 and 10 bytes into a region of size 9 [-Werror=format-truncation=]
> 2836 |                 snprintf(pvname, sizeof(pvname), "pv_ops[%d]", idx);
> 
> Signed-off-by: Martin Liška <mliska@suse.cz>
> ---
>  tools/objtool/check.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/tools/objtool/check.c b/tools/objtool/check.c
> index a9a1f7259d62..9555f7ad57cd 100644
> --- a/tools/objtool/check.c
> +++ b/tools/objtool/check.c
> @@ -2852,7 +2852,7 @@ static inline bool func_uaccess_safe(struct symbol
> *func)
>  
>  static inline const char *call_dest_name(struct instruction *insn)
>  {
> -	static char pvname[16];
> +	static char pvname[20];
>  	struct reloc *rel;
>  	int idx;

a similar patch has already been posted (not merged yet though).

https://lore.kernel.org/all/20211223182707.42590-1-kilobyte@angband.pl/

Thanks

Miroslav

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-01-12  9:41 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-12  9:29 [PATCH] objtool: Fix -Wformat-truncation seen with GCC 12 Martin Liška
2022-01-12  9:38 ` David Laight
2022-01-12  9:41 ` Miroslav Benes

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).