[0/5] Fix compiler warnings from GCC-10

Message ID 20201130002135.6537-1-stephen@networkplumber.org
Headers show
Series
  • Fix compiler warnings from GCC-10
Related show

Message

Stephen Hemminger Nov. 30, 2020, 12:21 a.m.
Update to GCC-10 and it starts warning about some new things.

Stephen Hemminger (5):
  devlink: fix uninitialized warning
  bridge: fix string length warning
  tc: fix compiler warnings in ip6 pedit
  misc: fix compiler warning in ifstat and nstat
  f_u32: fix compiler gcc-10 compiler warning

 devlink/devlink.c  | 2 +-
 ip/iplink_bridge.c | 2 +-
 misc/ifstat.c      | 2 +-
 misc/nstat.c       | 3 +--
 tc/f_u32.c         | 2 +-
 tc/p_ip6.c         | 2 +-
 6 files changed, 6 insertions(+), 7 deletions(-)

Comments

David Laight Nov. 30, 2020, 9:18 a.m. | #1
From: Stephen Hemminger
> Sent: 30 November 2020 00:22
> 
> The code here was doing strncpy() in a way that causes gcc 10
> warning about possible string overflow. Just use strlcpy() which
> will null terminate and bound the string as expected.
> 
> This has existed since start of git era so no Fixes tag.
> 
> Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
> ---
>  misc/ifstat.c | 2 +-
>  misc/nstat.c  | 3 +--
>  2 files changed, 2 insertions(+), 3 deletions(-)
> 
> diff --git a/misc/ifstat.c b/misc/ifstat.c
> index c05183d79a13..d4a33429dc50 100644
> --- a/misc/ifstat.c
> +++ b/misc/ifstat.c
> @@ -251,7 +251,7 @@ static void load_raw_table(FILE *fp)
>  			buf[strlen(buf)-1] = 0;
>  			if (info_source[0] && strcmp(info_source, buf+1))
>  				source_mismatch = 1;
> -			strncpy(info_source, buf+1, sizeof(info_source)-1);
> +			strlcpy(info_source, buf+1, sizeof(info_source));
>  			continue;

ISTM that once it has done a strlen() it ought to use the length
for the later copy.

I don't seem to have the source file (I'm guessing it isn't in the
normal repo), but is that initial strlen() guaranteed not to return
zero?

	David

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)
Stephen Hemminger Nov. 30, 2020, 5:31 p.m. | #2
On Mon, 30 Nov 2020 09:18:59 +0000
David Laight <David.Laight@ACULAB.COM> wrote:

> From: Stephen Hemminger
> > Sent: 30 November 2020 00:22
> > 
> > The code here was doing strncpy() in a way that causes gcc 10
> > warning about possible string overflow. Just use strlcpy() which
> > will null terminate and bound the string as expected.
> > 
> > This has existed since start of git era so no Fixes tag.
> > 
> > Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
> > ---
> >  misc/ifstat.c | 2 +-
> >  misc/nstat.c  | 3 +--
> >  2 files changed, 2 insertions(+), 3 deletions(-)
> > 
> > diff --git a/misc/ifstat.c b/misc/ifstat.c
> > index c05183d79a13..d4a33429dc50 100644
> > --- a/misc/ifstat.c
> > +++ b/misc/ifstat.c
> > @@ -251,7 +251,7 @@ static void load_raw_table(FILE *fp)
> >  			buf[strlen(buf)-1] = 0;
> >  			if (info_source[0] && strcmp(info_source, buf+1))
> >  				source_mismatch = 1;
> > -			strncpy(info_source, buf+1, sizeof(info_source)-1);
> > +			strlcpy(info_source, buf+1, sizeof(info_source));
> >  			continue;  
> 
> ISTM that once it has done a strlen() it ought to use the length
> for the later copy.
> 
> I don't seem to have the source file (I'm guessing it isn't in the
> normal repo), but is that initial strlen() guaranteed not to return
> zero?
> 
> 	David
> 
> -
> Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
> Registration No: 1397386 (Wales)
> 

All this is in the regular iproute2 repo
Petr Machata Nov. 30, 2020, 11:10 p.m. | #3
Stephen Hemminger <stephen@networkplumber.org> writes:

> Gcc-10 complains about referencing a zero size array.
> This occurs because the array of keys is actually in the following
> structure which is part of the overall selector.
>
> The original code was safe, but better to just use the key
> array directly.
>
> Fixes: 2d9a8dc439ee ("tc: p_ip6: Support pedit of IPv6 dsfield")
> Cc: petrm@mellanox.com
> Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>

Reviewed-by: Petr Machata <petrm@nvidia.com>
patchwork-bot+netdevbpf@kernel.org Dec. 3, 2020, 4:40 p.m. | #4
Hello:

This series was applied to iproute2/iproute2.git (refs/heads/main):

On Sun, 29 Nov 2020 16:21:30 -0800 you wrote:
> Update to GCC-10 and it starts warning about some new things.

> 

> Stephen Hemminger (5):

>   devlink: fix uninitialized warning

>   bridge: fix string length warning

>   tc: fix compiler warnings in ip6 pedit

>   misc: fix compiler warning in ifstat and nstat

>   f_u32: fix compiler gcc-10 compiler warning

> 

> [...]


Here is the summary with links:
  - [1/5] devlink: fix uninitialized warning
    https://git.kernel.org/pub/scm/network/iproute2/iproute2.git/commit/?id=f8176999390f
  - [2/5] bridge: fix string length warning
    https://git.kernel.org/pub/scm/network/iproute2/iproute2.git/commit/?id=5bdc4e9151a1
  - [3/5] tc: fix compiler warnings in ip6 pedit
    https://git.kernel.org/pub/scm/network/iproute2/iproute2.git/commit/?id=2319db905295
  - [4/5] misc: fix compiler warning in ifstat and nstat
    https://git.kernel.org/pub/scm/network/iproute2/iproute2.git/commit/?id=c01498392138
  - [5/5] f_u32: fix compiler gcc-10 compiler warning
    https://git.kernel.org/pub/scm/network/iproute2/iproute2.git/commit/?id=cae2e9291adf

You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html