From patchwork Wed May 30 07:46:35 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jim Meyering X-Patchwork-Id: 161909 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 2099DB700D for ; Wed, 30 May 2012 19:28:08 +1000 (EST) Received: from localhost ([::1]:58589 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SZddd-0001eB-HR for incoming@patchwork.ozlabs.org; Wed, 30 May 2012 03:48:13 -0400 Received: from eggs.gnu.org ([208.118.235.92]:47615) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SZdd9-0000ms-Kj for qemu-devel@nongnu.org; Wed, 30 May 2012 03:47:50 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SZdd7-0001kd-Vo for qemu-devel@nongnu.org; Wed, 30 May 2012 03:47:43 -0400 Received: from mx.meyering.net ([88.168.87.75]:49329 helo=hx.meyering.net) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SZdd7-0001kB-Kp for qemu-devel@nongnu.org; Wed, 30 May 2012 03:47:41 -0400 Received: from hx.meyering.net (hx.meyering.net [127.0.0.1]) by hx.meyering.net (8.14.5/8.14.5) with ESMTP id q4U7ldpT014029; Wed, 30 May 2012 09:47:39 +0200 Received: (from meyering@localhost) by hx.meyering.net (8.14.5/8.14.5/Submit) id q4U7ldNc014028; Wed, 30 May 2012 09:47:39 +0200 From: Jim Meyering To: qemu-devel@nongnu.org Date: Wed, 30 May 2012 09:46:35 +0200 Message-Id: <1338364001-13892-17-git-send-email-jim@meyering.net> X-Mailer: git-send-email 1.7.10.2.605.gbefc5ed In-Reply-To: <1338364001-13892-1-git-send-email-jim@meyering.net> References: <1338364001-13892-1-git-send-email-jim@meyering.net> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 88.168.87.75 Cc: Jim Meyering Subject: [Qemu-devel] [PATCHv2 16/22] qemu-ga: prefer pstrcpy: consistently NUL-terminate ifreq.ifr_name X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Jim Meyering 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 --- qga/commands-posix.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/qga/commands-posix.c b/qga/commands-posix.c index dab3bf9..607aad7 100644 --- a/qga/commands-posix.c +++ b/qga/commands-posix.c @@ -759,7 +759,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",