All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Jason A. Donenfeld" <Jason@zx2c4.com>
To: Gabriel Krisman Bertazi <krisman@suse.de>
Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org,
	krisman@collabora.com, jirislaby@kernel.org,
	stable@vger.kernel.org
Subject: Re: [PATCH v2] unicode: don't write -1 after NUL terminator
Date: Mon, 7 Nov 2022 16:09:58 +0100	[thread overview]
Message-ID: <Y2kfxmf3x5bF6tkR@zx2c4.com> (raw)
In-Reply-To: <87sfiux1q2.fsf@suse.de>

Hi Gabriel,

On Mon, Nov 07, 2022 at 09:45:25AM -0500, Gabriel Krisman Bertazi wrote:
> "Jason A. Donenfeld" <Jason@zx2c4.com> writes:
> 
> > If the intention is to overwrite the first NUL with a -1, s[strlen(s)]
> > is the first NUL, not s[strlen(s)+1].
> 
> Hi Jason,
> 
> This code is part of the verification of the trie that done at the end
> of utf8data generation. It is making sure the tree is not corrupted, by
> ensuring that utf8byte doesn't see something past the correct end of the
> string (the first NULL byte).  Note it is not a bad memory access
> either, since we guarantee to have allocated enough space.
> 
> So I think the code is correct as is. if you apply your patch and
> regenerate utf8data.h_shipped, utf8byte will reach that -1 and fail the
> verification.

Ah, okay. "Replace NUL" would seem to be wrong/confusing comment text I
suppose. Thanks for the explanation anyhow, and sorry for the noise.

Jason

> 
> > Cc: Gabriel Krisman Bertazi <krisman@collabora.com>
> > Cc: stable@vger.kernel.org
> > Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
> > ---
> >  fs/unicode/mkutf8data.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/fs/unicode/mkutf8data.c b/fs/unicode/mkutf8data.c
> > index bc1a7c8b5c8d..61800e0d3226 100644
> > --- a/fs/unicode/mkutf8data.c
> > +++ b/fs/unicode/mkutf8data.c
> > @@ -3194,7 +3194,7 @@ static int normalize_line(struct tree *tree)
> >  	/* Second test: length-limited string. */
> >  	s = buf2;
> >  	/* Replace NUL with a value that will cause an error if seen. */
> > -	s[strlen(s) + 1] = -1;
> > +	s[strlen(s)] = -1;
> >  	t = buf3;
> >  	if (utf8cursor(&u8c, tree, s))
> >  		return -1;
> 
> -- 
> Gabriel Krisman Bertazi

      reply	other threads:[~2022-11-07 15:10 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-03  1:24 [PATCH] unicode: don't write -1 after NULL terminator Jason A. Donenfeld
2022-11-03  7:00 ` Jiri Slaby
2022-11-03 11:30   ` [PATCH v2] unicode: don't write -1 after NUL terminator Jason A. Donenfeld
2022-11-07 14:45     ` Gabriel Krisman Bertazi
2022-11-07 15:09       ` Jason A. Donenfeld [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=Y2kfxmf3x5bF6tkR@zx2c4.com \
    --to=jason@zx2c4.com \
    --cc=jirislaby@kernel.org \
    --cc=krisman@collabora.com \
    --cc=krisman@suse.de \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=stable@vger.kernel.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.