On 4/30/19 3:08 PM, Alistair Francis wrote: > Fix this warning when building with GCC9 on Fedora 30: > In function ‘strncpy’, > inlined from ‘unix_connect_saddr.isra.0’ at util/qemu-sockets.c:925:5: > /usr/include/bits/string_fortified.h:106:10: error: ‘__builtin_strncpy’ > specified bound 108 equals destination size [-Werror=stringop-truncation] > 106 | return __builtin___strncpy_chk (__dest, __src, __len, __bos > (__dest)); > | > ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > In function ‘strncpy’, > inlined from ‘unix_listen_saddr.isra.0’ at util/qemu-sockets.c:880:5: > > Signed-off-by: Alistair Francis <alistair.fran...@wdc.com> > --- > util/qemu-sockets.c | 4 ++-- > 1 file changed, 2 insertions(+), 2 deletions(-) > > diff --git a/util/qemu-sockets.c b/util/qemu-sockets.c > index 9705051690..4322652428 100644 > --- a/util/qemu-sockets.c > +++ b/util/qemu-sockets.c > @@ -877,7 +877,7 @@ static int unix_listen_saddr(UnixSocketAddress *saddr, > > memset(&un, 0, sizeof(un)); > un.sun_family = AF_UNIX; > - strncpy(un.sun_path, path, sizeof(un.sun_path)); > + strncpy(un.sun_path, path, sizeof(un.sun_path) - 1);
NACK. Linux allows you to use the full width of un.sun_path (a NUL terminator is required if you copy less than that, but not if you use the full width). Rather, we may need to mark path as a potential nonstring to silence the warning, or use memcpy instead of strncpy, or some other workaround. (Sadly, this is one of those odd places where strncpy is actually the right function to use, but there are so many other places where strncpy is used incorrectly that it has turned into a battle to use it here) -- Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3226 Virtualization: qemu.org | libvirt.org
signature.asc
Description: OpenPGP digital signature