diff mbox series

unicode: don't write -1 after NULL terminator

Message ID 20221103012411.86537-1-Jason@zx2c4.com (mailing list archive)
State New, archived
Headers show
Series unicode: don't write -1 after NULL terminator | expand

Commit Message

Jason A. Donenfeld Nov. 3, 2022, 1:24 a.m. UTC
If the intention is to overwrite the first NULL with a -1, s[strlen(s)]
is the first NULL, not s[strlen(s)+1].

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(-)

Comments

Jiri Slaby Nov. 3, 2022, 7 a.m. UTC | #1
On 03. 11. 22, 2:24, Jason A. Donenfeld wrote:
> If the intention is to overwrite the first NULL with a -1, s[strlen(s)]
> is the first NULL, not s[strlen(s)+1].

This caught my attention. You mix NULL (void *) with NUL (\0) in the 
changelog & subject. That occurs rather confusing to me.

> 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;
diff mbox series

Patch

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;