From patchwork Mon Aug 20 16:55:21 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jim Meyering X-Patchwork-Id: 1350351 Return-Path: X-Original-To: patchwork-v9fs-devel@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from lists.sourceforge.net (lists.sourceforge.net [216.34.181.88]) by patchwork1.kernel.org (Postfix) with ESMTP id 148BB3FC33 for ; Mon, 20 Aug 2012 17:29:58 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=sfs-ml-3.v29.ch3.sourceforge.com) by sfs-ml-3.v29.ch3.sourceforge.com with esmtp (Exim 4.76) (envelope-from ) id 1T3VnI-0003B2-LI; Mon, 20 Aug 2012 17:29:40 +0000 Received: from sog-mx-3.v43.ch3.sourceforge.com ([172.29.43.193] helo=mx.sourceforge.net) by sfs-ml-3.v29.ch3.sourceforge.com with esmtp (Exim 4.76) (envelope-from ) id 1T3VnH-0003Av-Gt for v9fs-developer@lists.sourceforge.net; Mon, 20 Aug 2012 17:29:39 +0000 Received-SPF: pass (sog-mx-3.v43.ch3.sourceforge.com: domain of meyering.net designates 88.168.87.75 as permitted sender) client-ip=88.168.87.75; envelope-from=meyering@meyering.net; helo=hx.meyering.net; Received: from mx.meyering.net ([88.168.87.75] helo=hx.meyering.net) by sog-mx-3.v43.ch3.sourceforge.com with esmtps (TLSv1:AES256-SHA:256) (Exim 4.76) id 1T3VnG-00066L-40 for v9fs-developer@lists.sourceforge.net; Mon, 20 Aug 2012 17:29:39 +0000 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 q7KGtvs5030299; Mon, 20 Aug 2012 18:55:57 +0200 Received: (from meyering@localhost) by hx.meyering.net (8.14.5/8.14.5/Submit) id q7KGtsAx030297; Mon, 20 Aug 2012 18:55:54 +0200 From: Jim Meyering To: linux-kernel@vger.kernel.org Date: Mon, 20 Aug 2012 18:55:21 +0200 Message-Id: <1345481724-30108-3-git-send-email-jim@meyering.net> X-Mailer: git-send-email 1.7.12 In-Reply-To: <1345481724-30108-1-git-send-email-jim@meyering.net> References: <1345481724-30108-1-git-send-email-jim@meyering.net> X-Spam-Score: -1.6 (-) X-Spam-Report: Spam Filtering performed by mx.sourceforge.net. See http://spamassassin.org/tag/ for more details. -1.5 SPF_CHECK_PASS SPF reports sender host as permitted sender for sender-domain -0.0 SPF_HELO_PASS SPF: HELO matches SPF record -0.0 SPF_PASS SPF: sender matches SPF record -0.2 RP_MATCHES_RCVD Envelope sender domain matches handover relay domain 0.1 AWL AWL: From: address is in the auto white-list X-Headers-End: 1T3VnG-00066L-40 Cc: Jim Meyering , Eric Van Hensbergen , v9fs-developer@lists.sourceforge.net, Latchesar Ionkov , Ron Minnich Subject: [V9fs-developer] [PATCH] fs/9p: avoid debug OOPS when reading a long symlink X-BeenThere: v9fs-developer@lists.sourceforge.net X-Mailman-Version: 2.1.9 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: v9fs-developer-bounces@lists.sourceforge.net From: Jim Meyering Reading a symlink longer than the given buffer, a p9_debug use would try to print the link name (not NUL-terminated) using a %s format. Use %.*s instead, and replace the strncpy+strnlen with functionally equivalent strlen+memcpy. Signed-off-by: Jim Meyering --- fs/9p/vfs_inode.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/fs/9p/vfs_inode.c b/fs/9p/vfs_inode.c index cbf9dbb..16ed405 100644 --- a/fs/9p/vfs_inode.c +++ b/fs/9p/vfs_inode.c @@ -1276,12 +1276,12 @@ static int v9fs_readlink(struct dentry *dentry, char *buffer, int buflen) } /* copy extension buffer into buffer */ - strncpy(buffer, st->extension, buflen); + retval = min(strlen(st->extension)+1, buflen); + memcpy(buffer, st->extension, retval); - p9_debug(P9_DEBUG_VFS, "%s -> %s (%s)\n", - dentry->d_name.name, st->extension, buffer); + p9_debug(P9_DEBUG_VFS, "%s -> %s (%.*s)\n", + dentry->d_name.name, st->extension, buflen, buffer); - retval = strnlen(buffer, buflen); done: p9stat_free(st); kfree(st);