Date: Tue, 25 Aug 2015 09:16:09 +0000 (UTC) From: Ed Schouten <ed@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r287125 - head/lib/libc/locale Message-ID: <201508250916.t7P9G9vu037430@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: ed Date: Tue Aug 25 09:16:09 2015 New Revision: 287125 URL: https://svnweb.freebsd.org/changeset/base/287125 Log: Make UTF-8 parsing and generation more strict. - in mbrtowc() we need to disallow codepoints above 0x10ffff. - In wcrtomb() we need to disallow codepoints between 0xd800 and 0xdfff. Reviewed by: bapt Differential Revision: https://reviews.freebsd.org/D3399 Modified: head/lib/libc/locale/utf8.c Modified: head/lib/libc/locale/utf8.c ============================================================================== --- head/lib/libc/locale/utf8.c Tue Aug 25 06:12:59 2015 (r287124) +++ head/lib/libc/locale/utf8.c Tue Aug 25 09:16:09 2015 (r287125) @@ -191,7 +191,7 @@ _UTF8_mbrtowc(wchar_t * __restrict pwc, errno = EILSEQ; return ((size_t)-1); } - if (wch >= 0xd800 && wch <= 0xdfff) { + if ((wch >= 0xd800 && wch <= 0xdfff) || wch > 0x10ffff) { /* * Malformed input; invalid code points. */ @@ -318,6 +318,10 @@ _UTF8_wcrtomb(char * __restrict s, wchar lead = 0xc0; len = 2; } else if ((wc & ~0xffff) == 0) { + if (wc >= 0xd800 && wc <= 0xdfff) { + errno = EILSEQ; + return ((size_t)-1); + } lead = 0xe0; len = 3; } else if (wc >= 0 && wc <= 0x10ffff) {
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201508250916.t7P9G9vu037430>