From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47124) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WLwVy-0004lS-0a for qemu-devel@nongnu.org; Fri, 07 Mar 2014 10:16:55 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WLwVj-000530-CN for qemu-devel@nongnu.org; Fri, 07 Mar 2014 10:16:45 -0500 Received: from e28smtp08.in.ibm.com ([122.248.162.8]:36072) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WLwVi-00052K-PZ for qemu-devel@nongnu.org; Fri, 07 Mar 2014 10:16:31 -0500 Received: from /spool/local by e28smtp08.in.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Fri, 7 Mar 2014 20:46:28 +0530 Received: from d28relay05.in.ibm.com (d28relay05.in.ibm.com [9.184.220.62]) by d28dlp01.in.ibm.com (Postfix) with ESMTP id BC607E0044 for ; Fri, 7 Mar 2014 20:50:07 +0530 (IST) Received: from d28av03.in.ibm.com (d28av03.in.ibm.com [9.184.220.65]) by d28relay05.in.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id s27FGUQI42532946 for ; Fri, 7 Mar 2014 20:46:30 +0530 Received: from d28av03.in.ibm.com (localhost [127.0.0.1]) by d28av03.in.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id s27FGPS3017198 for ; Fri, 7 Mar 2014 20:46:25 +0530 From: "Aneesh Kumar K.V" Date: Fri, 7 Mar 2014 20:46:18 +0530 Message-Id: <1394205380-31875-4-git-send-email-aneesh.kumar@linux.vnet.ibm.com> In-Reply-To: <1394205380-31875-1-git-send-email-aneesh.kumar@linux.vnet.ibm.com> References: <1394205380-31875-1-git-send-email-aneesh.kumar@linux.vnet.ibm.com> Subject: [Qemu-devel] [PATCH 3/5] hw/9pfs/virtio-9p-local.c: use snprintf() instead of sprintf() List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: anthony@codemonkey.ws, peter.maydell@linaro.org Cc: "Aneesh Kumar K.V" , qemu-devel@nongnu.org, Chen Gang From: Chen Gang 'ctx->fs_root' + 'path'/'fullname.data' may be larger than PATH_MAX, so need use snprintf() instead of sprintf() just like another area have done in 9pfs. This could possibly result in the truncation of pathname, which we address in the follow up patch. Signed-off-by: Chen Gang Signed-off-by: Aneesh Kumar K.V --- hw/9pfs/virtio-9p-local.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/hw/9pfs/virtio-9p-local.c b/hw/9pfs/virtio-9p-local.c index 62e694370f34..dc615a4d0fa4 100644 --- a/hw/9pfs/virtio-9p-local.c +++ b/hw/9pfs/virtio-9p-local.c @@ -898,7 +898,8 @@ static int local_remove(FsContext *ctx, const char *path) * directory */ if (S_ISDIR(stbuf.st_mode)) { - sprintf(buffer, "%s/%s/%s", ctx->fs_root, path, VIRTFS_META_DIR); + snprintf(buffer, ARRAY_SIZE(buffer), "%s/%s/%s", + ctx->fs_root, path, VIRTFS_META_DIR); err = remove(buffer); if (err < 0 && errno != ENOENT) { /* @@ -1033,8 +1034,8 @@ static int local_unlinkat(FsContext *ctx, V9fsPath *dir, * If directory remove .virtfs_metadata contained in the * directory */ - sprintf(buffer, "%s/%s/%s", ctx->fs_root, - fullname.data, VIRTFS_META_DIR); + snprintf(buffer, ARRAY_SIZE(buffer), "%s/%s/%s", ctx->fs_root, + fullname.data, VIRTFS_META_DIR); ret = remove(buffer); if (ret < 0 && errno != ENOENT) { /* -- 1.8.3.2