From: Jim Meyering Date: Thu, 4 Oct 2012 11:09:58 +0000 (+0200) Subject: qemu-ga: prefer pstrcpy: consistently NUL-terminate ifreq.ifr_name X-Git-Tag: v1.3.0-rc0~378 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=1ab516ed9b6ba00bafc5ca37604f8af4680323ca;p=thirdparty%2Fqemu.git qemu-ga: prefer pstrcpy: consistently NUL-terminate ifreq.ifr_name NUL-termination of the .ifr_name field is not required, but is fine (and preferable to using strncpy and leaving the reader to wonder), since the first thing the linux kernel does is to clear the last byte. Besides, using pstrcpy here makes this setting of ifr_name consistent with the other code (e.g., net/tap-linux.c) that does the same thing. Reviewed-by: Luiz Capitulino Signed-off-by: Jim Meyering Signed-off-by: Anthony Liguori --- diff --git a/qga/commands-posix.c b/qga/commands-posix.c index ce9042123cd..b9f357cb967 100644 --- a/qga/commands-posix.c +++ b/qga/commands-posix.c @@ -828,7 +828,7 @@ GuestNetworkInterfaceList *qmp_guest_network_get_interfaces(Error **errp) } memset(&ifr, 0, sizeof(ifr)); - strncpy(ifr.ifr_name, info->value->name, IF_NAMESIZE); + pstrcpy(ifr.ifr_name, IF_NAMESIZE, info->value->name); if (ioctl(sock, SIOCGIFHWADDR, &ifr) == -1) { snprintf(err_msg, sizeof(err_msg), "failed to get MAC address of %s: %s",