Send connman mailing list submissions to
        [email protected]

To subscribe or unsubscribe via email, send a message with subject or
body 'help' to
        [email protected]

You can reach the person managing the list at
        [email protected]

When replying, please edit your Subject line so it is more specific
than "Re: Contents of connman digest..."

Today's Topics:

   1. Re: [PATCH] plugins/ethernet: fix strncpy errors with GCC>9.1
      (nick83ola)


----------------------------------------------------------------------

Date: Sun, 20 Oct 2019 14:29:29 +0100
From: nick83ola <[email protected]>
Subject: Re: [PATCH] plugins/ethernet: fix strncpy errors with GCC>9.1
To: Böszörményi Zoltán <[email protected]>
Cc: [email protected]
Message-ID:
        <CABPh3UNha+mYB=qKQt-zU0YhbKPX0jXEwGCTH-7XZy=ed6t...@mail.gmail.com>
Content-Type: text/plain; charset="UTF-8"

Hi to all,
I'm not totally sure about this part

+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wstringop-truncation"
        if(ioctl(sk, SIOCSIFVLAN, &vifr) >= 0)
-               strncpy(ifr.ifr_name, vifr.u.device2, sizeof(ifr.ifr_name));
+               strncpy(ifr.ifr_name, vifr.u.device2, sizeof(ifr.ifr_name) - 1);
+#pragma GCC diagnostic pop

The problem is that ifr_name and device2 are defined on my system with
two different length

What to do in this case?

The rest should be fine

Best Regards
Nicola Lunghi



On Sun, 20 Oct 2019 at 06:40, Böszörményi Zoltán <[email protected]> wrote:
>
> 2019. 10. 16. 19:01 keltezéssel, Nicola Lunghi írta:
> > From: Nicola Lunghi <[email protected]>
> >
> > This fixes the following errors:
> >
> > In function ‘strncpy’,
> >      inlined from ‘get_dsa_port’ at plugins/ethernet.c:102:2:
> > /usr/include/x86_64-linux-gnu/bits/string_fortified.h:106:10:
> >    error: ‘__builtin_strncpy’ specified bound 16 equals destination size
> >           [-Werror=stringop-truncation]
> >    106 |  return __builtin___strncpy_chk (__dest, __src, __len, __bos 
> > (__dest));
> >        |          
> > ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> > In function ‘strncpy’,
> >      inlined from ‘get_dsa_port’ at plugins/ethernet.c:106:2:
> > /usr/include/x86_64-linux-gnu/bits/string_fortified.h:106:10:
> >    error: ‘__builtin_strncpy’ specified bound 24 equals destination size
> >           [-Werror=stringop-truncation]
> >    106 |  return __builtin___strncpy_chk (__dest, __src, __len, __bos 
> > (__dest));
> >        |          
> > ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> > In function ‘strncpy’,
> >      inlined from ‘get_dsa_port’ at plugins/ethernet.c:109:3:
> > /usr/include/x86_64-linux-gnu/bits/string_fortified.h:106:10:
> >    error: ‘__builtin_strncpy’ output may be truncated copying 16 bytes
> >           from a string of length 23 [-Werror=stringop-truncation]
> >    106 |  return __builtin___strncpy_chk (__dest, __src, __len, __bos 
> > (__dest));
> >        |          
> > ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> >    CC       plugins/src_connmand-neard.o
> >    CC       src/shared/connmand-util.o
> >    CC       src/shared/connmand-netlink.o
> >    CC       src/shared/connmand-arp.o
> > In function ‘strncpy’,
> >      inlined from ‘get_vlan_vid’ at plugins/ethernet.c:76:2,
> >      inlined from ‘add_network’ at plugins/ethernet.c:199:9,
> >      inlined from ‘ethernet_newlink’ at plugins/ethernet.c:253:4:
> > /usr/include/x86_64-linux-gnu/bits/string_fortified.h:106:10:
> >    error: ‘__builtin_strncpy’ specified bound 24 equals destination size
> >           [-Werror=stringop-truncation]
> >    106 |  return __builtin___strncpy_chk (__dest, __src, __len, __bos 
> > (__dest));
> >        |          
> > ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> >
> > Signed-off-by: Nicola Lunghi <[email protected]>
> > ---
> >   plugins/ethernet.c | 11 +++++++----
> >   1 file changed, 7 insertions(+), 4 deletions(-)
> >
> > diff --git a/plugins/ethernet.c b/plugins/ethernet.c
> > index b0395c83..6ceb2266 100644
> > --- a/plugins/ethernet.c
> > +++ b/plugins/ethernet.c
> > @@ -73,7 +73,7 @@ static int get_vlan_vid(const char *ifname)
> >               return -errno;
> >
> >       vifr.cmd = GET_VLAN_VID_CMD;
> > -     strncpy(vifr.device1, ifname, sizeof(vifr.device1));
> > +     strncpy(vifr.device1, ifname, sizeof(vifr.device1) - 1);
>
> This is a stable pattern that also ensures the string to get
> zero-terminated (strncpy or stpncpy alone don't but with strncpy,
> you would also need an strlen on the original to find the length):
>
> char *end = stpncpy(vifr.device1, ifname, sizeof(vifr.device1) - 1);
> *end = 0;
>
> >
> >       if(ioctl(sk, SIOCSIFVLAN, &vifr) >= 0)
> >               vid = vifr.u.VID;
> > @@ -99,14 +99,17 @@ static int get_dsa_port(const char *ifname)
> >               return -errno;
> >
> >       memset(&ifr, 0, sizeof(ifr));
> > -     strncpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
> > +     strncpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name) - 1);
> >
> >       /* check if it is a vlan and get physical interface name*/
> >       vifr.cmd = GET_VLAN_REALDEV_NAME_CMD;
> > -     strncpy(vifr.device1, ifname, sizeof(vifr.device1));
> > +     strncpy(vifr.device1, ifname, sizeof(vifr.device1) - 1);
> >
> > +#pragma GCC diagnostic push
> > +#pragma GCC diagnostic ignored "-Wstringop-truncation"
> >       if(ioctl(sk, SIOCSIFVLAN, &vifr) >= 0)
> > -             strncpy(ifr.ifr_name, vifr.u.device2, sizeof(ifr.ifr_name));
> > +             strncpy(ifr.ifr_name, vifr.u.device2, sizeof(ifr.ifr_name) - 
> > 1);
> > +#pragma GCC diagnostic pop
> >
> >       /* get driver info */
> >       drvinfocmd.cmd =  ETHTOOL_GDRVINFO;
> >
>

------------------------------

Subject: Digest Footer

_______________________________________________
connman mailing list -- [email protected]
To unsubscribe send an email to [email protected]


------------------------------

End of connman Digest, Vol 48, Issue 26
***************************************

Reply via email to