From patchwork Tue Aug 21 07:20:49 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jim Meyering X-Patchwork-Id: 1352581 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 33BEF3FC81 for ; Tue, 21 Aug 2012 07:21:20 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=sfs-ml-1.v29.ch3.sourceforge.com) by sfs-ml-1.v29.ch3.sourceforge.com with esmtp (Exim 4.76) (envelope-from ) id 1T3ilq-0004Q3-6Y; Tue, 21 Aug 2012 07:21:02 +0000 Received: from sog-mx-4.v43.ch3.sourceforge.com ([172.29.43.194] helo=mx.sourceforge.net) by sfs-ml-1.v29.ch3.sourceforge.com with esmtp (Exim 4.76) (envelope-from ) id 1T3ilo-0004Ps-DV for v9fs-developer@lists.sourceforge.net; Tue, 21 Aug 2012 07:21:00 +0000 Received-SPF: pass (sog-mx-4.v43.ch3.sourceforge.com: domain of meyering.net designates 88.168.87.75 as permitted sender) client-ip=88.168.87.75; envelope-from=jim@meyering.net; helo=mx.meyering.net; Received: from mx.meyering.net ([88.168.87.75]) by sog-mx-4.v43.ch3.sourceforge.com with esmtp (Exim 4.76) id 1T3ilj-0002Uj-9p for v9fs-developer@lists.sourceforge.net; Tue, 21 Aug 2012 07:21:00 +0000 Received: from rho.meyering.net (rho.meyering.net [127.0.0.1]) by rho.meyering.net (Acme Bit-Twister) with ESMTP id 0C66260096; Tue, 21 Aug 2012 09:20:49 +0200 (CEST) From: Jim Meyering To: linux-kernel@vger.kernel.org In-Reply-To: <1345481724-30108-3-git-send-email-jim@meyering.net> (Jim Meyering's message of "Mon, 20 Aug 2012 18:55:21 +0200") References: <1345481724-30108-1-git-send-email-jim@meyering.net> <1345481724-30108-3-git-send-email-jim@meyering.net> Date: Tue, 21 Aug 2012 09:20:49 +0200 Message-ID: <87mx1ok8xa.fsf_-_@rho.meyering.net> Lines: 41 MIME-Version: 1.0 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_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: 1T3ilj-0002Uj-9p Cc: Eric Van Hensbergen , Ron Minnich , Latchesar Ionkov , v9fs-developer@lists.sourceforge.net Subject: [V9fs-developer] [PATCHv2] 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: , Errors-To: v9fs-developer-bounces@lists.sourceforge.net 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 --- V1 provoked a warning due to strlen/buflen type differences (size_t/int) and the "min" macro's type equality requirement. This adds a cast to avoid that warning: - retval = min(strlen(st->extension)+1, buflen); + retval = min(strlen(st->extension)+1, (size_t)buflen); fs/9p/vfs_inode.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) -- 1.7.12 ------------------------------------------------------------------------------ Live Security Virtual Conference Exclusive live event will cover all the ways today's security and threat landscape has changed and how IT managers can respond. Discussions will include endpoint security, mobile security and the latest in malware threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/ diff --git a/fs/9p/vfs_inode.c b/fs/9p/vfs_inode.c index cbf9dbb..890bed5 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, (size_t)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);