From: Gabriel Krisman Bertazi <krisman@suse.de>
To: "Jason A. Donenfeld" <Jason@zx2c4.com>
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, 07 Nov 2022 09:45:25 -0500 [thread overview]
Message-ID: <87sfiux1q2.fsf@suse.de> (raw)
In-Reply-To: <20221103113021.3271-1-Jason@zx2c4.com> (Jason A. Donenfeld's message of "Thu, 3 Nov 2022 12:30:21 +0100")
"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.
> 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
next prev parent reply other threads:[~2022-11-07 14:45 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 [this message]
2022-11-07 15:09 ` Jason A. Donenfeld
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=87sfiux1q2.fsf@suse.de \
--to=krisman@suse.de \
--cc=Jason@zx2c4.com \
--cc=jirislaby@kernel.org \
--cc=krisman@collabora.com \
--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 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).