From patchwork Wed May 9 09:23:55 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jim Meyering X-Patchwork-Id: 157965 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 96BC6B6FB4 for ; Thu, 10 May 2012 00:11:05 +1000 (EST) Received: from localhost ([::1]:57473 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SS6Va-0006qm-QZ for incoming@patchwork.ozlabs.org; Wed, 09 May 2012 09:00:46 -0400 Received: from eggs.gnu.org ([208.118.235.92]:34361) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SS388-00062n-E5 for qemu-devel@nongnu.org; Wed, 09 May 2012 05:24:26 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SS384-00028t-G1 for qemu-devel@nongnu.org; Wed, 09 May 2012 05:24:20 -0400 Received: from mx.meyering.net ([88.168.87.75]:36938) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SS384-00024p-6r for qemu-devel@nongnu.org; Wed, 09 May 2012 05:24:16 -0400 Received: by rho.meyering.net (Acme Bit-Twister, from userid 1000) id 1F3CC60C2E; Wed, 9 May 2012 11:24:13 +0200 (CEST) From: Jim Meyering To: qemu-devel@nongnu.org Date: Wed, 9 May 2012 11:23:55 +0200 Message-Id: <1336555446-20180-12-git-send-email-jim@meyering.net> X-Mailer: git-send-email 1.7.10 In-Reply-To: <1336555446-20180-1-git-send-email-jim@meyering.net> References: <1336555446-20180-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 X-Mailman-Approved-At: Wed, 09 May 2012 08:59:40 -0400 Cc: Jim Meyering , "Aneesh Kumar K.V" Subject: [Qemu-devel] [PATCH 11/22] virtio-9p: avoid unwarranted uses of strncpy 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 In both mp_pacl_listxattr and mp_dacl_listxattr, the uses of strncpy were unnecessary, since at each point of use we know that the NUL-terminated source bytes fit in the destination buffer. Use memcpy in place of strncpy. Signed-off-by: Jim Meyering --- hw/9pfs/virtio-9p-posix-acl.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/hw/9pfs/virtio-9p-posix-acl.c b/hw/9pfs/virtio-9p-posix-acl.c index a1948e3..c064017 100644 --- a/hw/9pfs/virtio-9p-posix-acl.c +++ b/hw/9pfs/virtio-9p-posix-acl.c @@ -44,7 +44,8 @@ static ssize_t mp_pacl_listxattr(FsContext *ctx, const char *path, return -1; } - strncpy(value, ACL_ACCESS, len); + /* len includes the trailing NUL */ + memcpy(value, ACL_ACCESS, len); return 0; } @@ -95,7 +96,8 @@ static ssize_t mp_dacl_listxattr(FsContext *ctx, const char *path, return -1; } - strncpy(value, ACL_DEFAULT, len); + /* len includes the trailing NUL */ + memcpy(value, ACL_ACCESS, len); return 0; }