diff options
author | ed <ed@FreeBSD.org> | 2015-08-25 09:16:09 +0000 |
---|---|---|
committer | ed <ed@FreeBSD.org> | 2015-08-25 09:16:09 +0000 |
commit | 94d0b79c32353fbed24d46514802bdb6c2018a42 (patch) | |
tree | 754a64ddbacad3efa192e7e6d3a11a5eaaf88f2b /lib | |
parent | abcfdaaaf0d4f8d1446e057bc5b55c4a75dab803 (diff) | |
download | FreeBSD-src-94d0b79c32353fbed24d46514802bdb6c2018a42.zip FreeBSD-src-94d0b79c32353fbed24d46514802bdb6c2018a42.tar.gz |
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
Diffstat (limited to 'lib')
-rw-r--r-- | lib/libc/locale/utf8.c | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/lib/libc/locale/utf8.c b/lib/libc/locale/utf8.c index 55e2931..8ccfdb1 100644 --- a/lib/libc/locale/utf8.c +++ b/lib/libc/locale/utf8.c @@ -191,7 +191,7 @@ _UTF8_mbrtowc(wchar_t * __restrict pwc, const char * __restrict s, size_t n, 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_t wc, mbstate_t * __restrict ps) 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) { |