patches.lists.linux.dev archive mirror
 help / color / mirror / Atom feed
From: NeilBrown <neilb@ownmail.net>
To: "Nathan Chancellor" <nathan@kernel.org>
Cc: "Chuck Lever" <chuck.lever@oracle.com>,
	"Jeff Layton" <jlayton@kernel.org>,
	"Anna Schumaker" <anna.schumaker@oracle.com>,
	"Olga Kornievskaia" <okorniev@redhat.com>,
	"Dai Ngo" <Dai.Ngo@oracle.com>, "Tom Talpey" <tom@talpey.com>,
	"Simon Horman" <horms@kernel.org>,
	linux-nfs@vger.kernel.org, patches@lists.linux.dev
Subject: Re: [PATCH v2] nfsd: Avoid strlen conflict in nfsd4_encode_components_esc()
Date: Tue, 30 Sep 2025 15:32:37 +1000	[thread overview]
Message-ID: <175921035791.1696783.9932533700998546063@noble.neil.brown.name> (raw)
In-Reply-To: <20250929181134.GA685251@ax162>

On Tue, 30 Sep 2025, Nathan Chancellor wrote:
> On Mon, Sep 29, 2025 at 09:05:15AM -0400, Chuck Lever wrote:
> > On 9/28/25 4:29 PM, NeilBrown wrote:
> > > On Mon, 29 Sep 2025, Nathan Chancellor wrote:
> ...
> > >> diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c
> > >> index ea91bad4eee2..9fe8a413f688 100644
> > >> --- a/fs/nfsd/nfs4xdr.c
> > >> +++ b/fs/nfsd/nfs4xdr.c
> > >> @@ -2640,11 +2640,9 @@ static __be32 nfsd4_encode_components_esc(struct xdr_stream *xdr, char sep,
> > >>  	__be32 *p;
> > >>  	__be32 pathlen;
> > >>  	int pathlen_offset;
> > >> -	int strlen, count=0;
> > >> +	int str_len, count=0;
> > >>  	char *str, *end, *next;
> > >>  
> > >> -	dprintk("nfsd4_encode_components(%s)\n", components);
> > >> -
> > >>  	pathlen_offset = xdr->buf->len;
> > >>  	p = xdr_reserve_space(xdr, 4);
> > >>  	if (!p)
> > >> @@ -2670,9 +2668,9 @@ static __be32 nfsd4_encode_components_esc(struct xdr_stream *xdr, char sep,
> > >>  			for (; *end && (*end != sep); end++)
> > >>  				/* find sep or end of string */;
> > >>  
> > >> -		strlen = end - str;
> > >> -		if (strlen) {
> > >> -			if (xdr_stream_encode_opaque(xdr, str, strlen) < 0)
> > >> +		str_len = end - str;
> > >> +		if (str_len) {
> > >> +			if (xdr_stream_encode_opaque(xdr, str, str_len) < 0)
> > >>  				return nfserr_resource;
> > > 
> > > I probably should have said something earlier, and this is definitely
> > > bike-shedding material, but .... "str_len" is not a whole lot nicer than
> > > "strlen" (or "i") ...
> > > 
> > > 
> > >    if (end > str) {
> > > 	if (xdr_stream_encode_opaque(xdr, str, end - str) < 0)
> > > 
> > > ??
> > 
> > "len" is actually the typical variable name used in such cases. But I
> > didn't want to bug Nathan for a resend.
> 
> If "len" is truly preferred, I do not mind sending a v3 with such a
> change. I had only kept "str" in the name because there is also
> "pathlen" in this function.


If you are going to send a v3 I would much prefer there were no variable
at all.  Just use
  if (end > str) {
    if (xdr_stream_encode_opaque(xdr, str, end - str) < 0) 
 ...


If we wanted a 'len' variable then I would change "str" to "component"
or some abbreviation there-of and use "componentlen" (or e.g.  cmpnt,
cmpntlen).  This function is encoding "components" so using suitably
named variables to focus the reader on which bits are the "components"
seems wise.

But as I say, we don't need a "len" variable, so I wouldn't bother
renaming "str" to "cmpnt" at this stage.

Thanks,
NeilBrown


      reply	other threads:[~2025-09-30  5:32 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-09-28 19:14 [PATCH v2] nfsd: Avoid strlen conflict in nfsd4_encode_components_esc() Nathan Chancellor
2025-09-28 19:56 ` Jeff Layton
2025-09-28 20:13 ` Chuck Lever
2025-09-28 23:29 ` NeilBrown
2025-09-29 13:05   ` Chuck Lever
2025-09-29 18:11     ` Nathan Chancellor
2025-09-30  5:32       ` NeilBrown [this message]

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=175921035791.1696783.9932533700998546063@noble.neil.brown.name \
    --to=neilb@ownmail.net \
    --cc=Dai.Ngo@oracle.com \
    --cc=anna.schumaker@oracle.com \
    --cc=chuck.lever@oracle.com \
    --cc=horms@kernel.org \
    --cc=jlayton@kernel.org \
    --cc=linux-nfs@vger.kernel.org \
    --cc=nathan@kernel.org \
    --cc=neil@brown.name \
    --cc=okorniev@redhat.com \
    --cc=patches@lists.linux.dev \
    --cc=tom@talpey.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).