netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH, net-next] net: ethernet: freescale: fix false-positive string overflow warning
@ 2018-05-28 15:49 Arnd Bergmann
  2018-05-29  1:10 ` Andy Duan
  2018-05-30 17:18 ` David Miller
  0 siblings, 2 replies; 3+ messages in thread
From: Arnd Bergmann @ 2018-05-28 15:49 UTC (permalink / raw)
  To: Fugang Duan, David S. Miller
  Cc: Arnd Bergmann, Fabio Estevam, Andrew Lunn, Troy Kisky,
	Florian Fainelli, netdev, linux-kernel

While compile-testing on arm64 with gcc-8.1, I ran into a build diagnostic:

drivers/net/ethernet/freescale/fec_main.c: In function 'fec_probe':
drivers/net/ethernet/freescale/fec_main.c:3517:25: error: '%d' directive writing between 1 and 10 bytes into a region of size 5 [-Werror=format-overflow=]
   sprintf(irq_name, "int%d", i);
                         ^~
drivers/net/ethernet/freescale/fec_main.c:3517:21: note: directive argument in the range [0, 2147483646]
   sprintf(irq_name, "int%d", i);
                     ^~~~~~~
drivers/net/ethernet/freescale/fec_main.c:3517:3: note: 'sprintf' output between 5 and 14 bytes into a destination of size 8
   sprintf(irq_name, "int%d", i);
   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~

It appears this has never shown on ppc32 or arm32 for an unknown reason, but
now gcc fails to identify that the 'irq_cnt' loop index has an upper bound
of 3, and instead uses a bogus range.

To work around the warning, this changes the sprintf to snprintf with the
correct buffer length.

Fixes: 78cc6e7ef957 ("net: ethernet: freescale: Allow FEC with COMPILE_TEST")
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
 drivers/net/ethernet/freescale/fec_main.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/freescale/fec_main.c b/drivers/net/ethernet/freescale/fec_main.c
index ab7521c04eb2..c729665107f5 100644
--- a/drivers/net/ethernet/freescale/fec_main.c
+++ b/drivers/net/ethernet/freescale/fec_main.c
@@ -3514,7 +3514,7 @@ fec_probe(struct platform_device *pdev)
 		goto failed_init;
 
 	for (i = 0; i < irq_cnt; i++) {
-		sprintf(irq_name, "int%d", i);
+		snprintf(irq_name, sizeof(irq_name), "int%d", i);
 		irq = platform_get_irq_byname(pdev, irq_name);
 		if (irq < 0)
 			irq = platform_get_irq(pdev, i);
-- 
2.9.0

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

* RE: [PATCH, net-next] net: ethernet: freescale: fix false-positive string overflow warning
  2018-05-28 15:49 [PATCH, net-next] net: ethernet: freescale: fix false-positive string overflow warning Arnd Bergmann
@ 2018-05-29  1:10 ` Andy Duan
  2018-05-30 17:18 ` David Miller
  1 sibling, 0 replies; 3+ messages in thread
From: Andy Duan @ 2018-05-29  1:10 UTC (permalink / raw)
  To: Arnd Bergmann, David S. Miller
  Cc: Fabio Estevam, Andrew Lunn, Troy Kisky, Florian Fainelli,
	netdev@vger.kernel.org, linux-kernel@vger.kernel.org

From: Arnd Bergmann <arnd@arndb.de> Sent: 2018年5月28日 23:50
> While compile-testing on arm64 with gcc-8.1, I ran into a build diagnostic:
> 
> drivers/net/ethernet/freescale/fec_main.c: In function 'fec_probe':
> drivers/net/ethernet/freescale/fec_main.c:3517:25: error: '%d' directive
> writing between 1 and 10 bytes into a region of size 5
> [-Werror=format-overflow=]
>    sprintf(irq_name, "int%d", i);
>                          ^~
> drivers/net/ethernet/freescale/fec_main.c:3517:21: note: directive
> argument in the range [0, 2147483646]
>    sprintf(irq_name, "int%d", i);
>                      ^~~~~~~
> drivers/net/ethernet/freescale/fec_main.c:3517:3: note: 'sprintf' output
> between 5 and 14 bytes into a destination of size 8
>    sprintf(irq_name, "int%d", i);
>    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> 
> It appears this has never shown on ppc32 or arm32 for an unknown
> reason, but now gcc fails to identify that the 'irq_cnt' loop index has an
> upper bound of 3, and instead uses a bogus range.
> 
> To work around the warning, this changes the sprintf to snprintf with the
> correct buffer length.
> 
> Fixes: 78cc6e7ef957 ("net: ethernet: freescale: Allow FEC with
> COMPILE_TEST")
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>

Acked-by: Fugang Duan <fugang.duan@nxp.com>

> ---
>  drivers/net/ethernet/freescale/fec_main.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/net/ethernet/freescale/fec_main.c
> b/drivers/net/ethernet/freescale/fec_main.c
> index ab7521c04eb2..c729665107f5 100644
> --- a/drivers/net/ethernet/freescale/fec_main.c
> +++ b/drivers/net/ethernet/freescale/fec_main.c
> @@ -3514,7 +3514,7 @@ fec_probe(struct platform_device *pdev)
>  		goto failed_init;
> 
>  	for (i = 0; i < irq_cnt; i++) {
> -		sprintf(irq_name, "int%d", i);
> +		snprintf(irq_name, sizeof(irq_name), "int%d", i);
>  		irq = platform_get_irq_byname(pdev, irq_name);
>  		if (irq < 0)
>  			irq = platform_get_irq(pdev, i);
> --
> 2.9.0


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

* Re: [PATCH, net-next] net: ethernet: freescale: fix false-positive string overflow warning
  2018-05-28 15:49 [PATCH, net-next] net: ethernet: freescale: fix false-positive string overflow warning Arnd Bergmann
  2018-05-29  1:10 ` Andy Duan
@ 2018-05-30 17:18 ` David Miller
  1 sibling, 0 replies; 3+ messages in thread
From: David Miller @ 2018-05-30 17:18 UTC (permalink / raw)
  To: arnd
  Cc: fugang.duan, fabio.estevam, andrew, troy.kisky, f.fainelli,
	netdev, linux-kernel

From: Arnd Bergmann <arnd@arndb.de>
Date: Mon, 28 May 2018 17:49:46 +0200

> While compile-testing on arm64 with gcc-8.1, I ran into a build diagnostic:
 ...
> It appears this has never shown on ppc32 or arm32 for an unknown reason, but
> now gcc fails to identify that the 'irq_cnt' loop index has an upper bound
> of 3, and instead uses a bogus range.
> 
> To work around the warning, this changes the sprintf to snprintf with the
> correct buffer length.
> 
> Fixes: 78cc6e7ef957 ("net: ethernet: freescale: Allow FEC with COMPILE_TEST")
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>

Applied, thanks Arnd.

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

end of thread, other threads:[~2018-05-30 17:18 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-05-28 15:49 [PATCH, net-next] net: ethernet: freescale: fix false-positive string overflow warning Arnd Bergmann
2018-05-29  1:10 ` Andy Duan
2018-05-30 17:18 ` David Miller

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).