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
(Böszörményi Zoltán)
----------------------------------------------------------------------
Date: Sun, 20 Oct 2019 07:40:01 +0200
From: Böszörményi Zoltán <[email protected]>
Subject: Re: [PATCH] plugins/ethernet: fix strncpy errors with GCC>9.1
To: Nicola Lunghi <[email protected]>, [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=utf-8; format=flowed
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 25
***************************************