linux-nfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Trond Myklebust <Trond.Myklebust@netapp.com>
To: "J. Bruce Fields" <bfields@fieldses.org>
Cc: Mi Jinlong <mijinlong@cn.fujitsu.com>,
	roel <roel.kluin@gmail.com>, Neil Brown <neilb@suse.de>,
	linux-nfs@vger.kernel.org,
	Andrew Morton <akpm@linux-foundation.org>,
	LKML <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] nfsd: wrong index used in inner loop
Date: Mon, 14 Mar 2011 19:52:11 -0400	[thread overview]
Message-ID: <1300146731.3026.4.camel@lade.trondhjem.org> (raw)
In-Reply-To: <20110314222229.GJ25442@fieldses.org>

On Mon, 2011-03-14 at 18:22 -0400, J. Bruce Fields wrote:
> On Fri, Mar 11, 2011 at 12:13:55PM +0800, Mi Jinlong wrote:
> > 
> > 
> > J. Bruce Fields:
> > > On Tue, Mar 08, 2011 at 10:32:26PM +0100, roel wrote:
> > >> Index i was already used in the outer loop
> > >>
> > >> Signed-off-by: Roel Kluin <roel.kluin@gmail.com>
> > >> ---
> > >>  fs/nfsd/nfs4xdr.c |    4 ++--
> > >>  1 files changed, 2 insertions(+), 2 deletions(-)
> > >>
> > >> Not 100% sure this one is needed but it looks suspicious.
> > > 
> > > Looks bad to me, thanks.
> > > 
> > > nfsd4_decode_create_session should probably really be broken up a little
> > > bit; if it wasn't so long this would have been more obvious.
> > > 
> > > I'll see if I can slip this into 2.6.38 with a couple other last-minute
> > > patches....  Otherwise, it'll be in 2.6.39.
> > > 
> > > --b.
> > > 
> > >> diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c
> > >> index 1275b86..615f0a9 100644
> > >> --- a/fs/nfsd/nfs4xdr.c
> > >> +++ b/fs/nfsd/nfs4xdr.c
> > >> @@ -1142,7 +1142,7 @@ nfsd4_decode_create_session(struct nfsd4_compoundargs *argp,
> > >>  
> > >>  	u32 dummy;
> > >>  	char *machine_name;
> > >> -	int i;
> > >> +	int i, j;
> > >>  	int nr_secflavs;
> > >>  
> > >>  	READ_BUF(16);
> > >> @@ -1215,7 +1215,7 @@ nfsd4_decode_create_session(struct nfsd4_compoundargs *argp,
> > >>  			READ_BUF(4);
> > >>  			READ32(dummy);
> > >>  			READ_BUF(dummy * 4);
> > >> -			for (i = 0; i < dummy; ++i)
> > >> +			for (j = 0; j < dummy; ++j)
> > >>  				READ32(dummy);
> > 
> >   We must not use dummy for index here.
> >   After the first index, READ32(dummy) will change dummy!!!!
> 
> Actually, wait, this is kind of silly.  I don't see why we couldn't just
> skip the loop and do
> 
> 	p += dummy;

This is exactly why I _hate_ the READ*() macros and their ilk, and am
really happy we got rid of them in the client.

READ_BUF() _sets_ p to whatever the value of argp->p is, and then
updates argp->p. It is just very very very hard to see that due to the
lack of transparency.

IOW: You don't need the "p += dummy" either. That happens automatically
when you next invoke READ_BUF().

Trond
-- 
Trond Myklebust
Linux NFS client maintainer

NetApp
Trond.Myklebust@netapp.com
www.netapp.com


  reply	other threads:[~2011-03-14 23:53 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-03-08 21:32 [PATCH] nfsd: wrong index used in inner loop roel
2011-03-09  0:49 ` J. Bruce Fields
2011-03-11  4:13   ` Mi Jinlong
2011-03-14 22:22     ` J. Bruce Fields
2011-03-14 23:52       ` Trond Myklebust [this message]
2011-03-16 22:55         ` J. Bruce Fields
2011-03-15  2:31       ` Mi Jinlong
2011-03-17 17:52         ` J. Bruce Fields
2011-03-09 23:42 ` Andrew Morton
2011-03-10 18:08   ` J. Bruce Fields
2011-03-11  3:52     ` Mi Jinlong
2011-03-14 19:35       ` J. Bruce Fields

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1300146731.3026.4.camel@lade.trondhjem.org \
    --to=trond.myklebust@netapp.com \
    --cc=akpm@linux-foundation.org \
    --cc=bfields@fieldses.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-nfs@vger.kernel.org \
    --cc=mijinlong@cn.fujitsu.com \
    --cc=neilb@suse.de \
    --cc=roel.kluin@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).