All of lore.kernel.org
 help / color / mirror / Atom feed
From: Michael Tretter <michael.tretter@posteo.net>
To: ell@lists.01.org
Subject: [PATCH 2/2] utf8: Fix expected bytes in l_utf8_get_codepoint
Date: Thu, 21 Mar 2019 00:31:45 +0100	[thread overview]
Message-ID: <20190320233145.8063-2-michael.tretter@posteo.net> (raw)
In-Reply-To: <20190320233145.8063-1-michael.tretter@posteo.net>

[-- Attachment #1: Type: text/plain, Size: 887 bytes --]

UTF-8 requires the form 10xxxxxx for the second, third and forth bytes
of a well-formed byte sequences. Therefore, comparing with 0 is not
sufficient to exclude ill-formed byte sequences, but the first two bit
must follow the specified form.

Without this check, iwd crashes if it encounters Latin-1 Supplement
encoded SSIDs during scanning, because they are erroneously accepted as
valid UTF-8.
---
 ell/utf8.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/ell/utf8.c b/ell/utf8.c
index e9998f7..f8750d8 100644
--- a/ell/utf8.c
+++ b/ell/utf8.c
@@ -109,7 +109,7 @@ LIB_EXPORT int l_utf8_get_codepoint(const char *str, size_t len, wchar_t *cp)
 	val = str[0] & (0xff >> (expect_bytes + 1));
 
 	for (i = 1; i < expect_bytes; i++) {
-		if ((str[i] & 0xc0) == 0)
+		if ((str[i] & 0xc0) != 0x80)
 			goto error;
 
 		val <<= 6;
-- 
2.21.0


  reply	other threads:[~2019-03-20 23:31 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-03-20 23:31 [PATCH 1/2] unit: add utf8_validate_test80 test Michael Tretter
2019-03-20 23:31 ` Michael Tretter [this message]
2019-03-21  1:09   ` [PATCH 2/2] utf8: Fix expected bytes in l_utf8_get_codepoint Denis Kenzior

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=20190320233145.8063-2-michael.tretter@posteo.net \
    --to=michael.tretter@posteo.net \
    --cc=ell@lists.01.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.