summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpfg <pfg@FreeBSD.org>2014-04-29 15:25:57 +0000
committerpfg <pfg@FreeBSD.org>2014-04-29 15:25:57 +0000
commitaa4f79bd1b9d9dce8f27070ef595729529a56807 (patch)
tree29bd5b654014f9c70803905b3009adcb132d7578
parentc95e6bbc4fc811dece236808ec0f0cc9c15254bb (diff)
downloadFreeBSD-src-aa4f79bd1b9d9dce8f27070ef595729529a56807.zip
FreeBSD-src-aa4f79bd1b9d9dce8f27070ef595729529a56807.tar.gz
citrus: Avoid invalid code points.
From the OpenBSD log: The UTF-8 decoder should not accept byte sequences which decode to unicode code positions U+D800 to U+DFFF (UTF-16 surrogates), U+FFFE, and U+FFFF. http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 http://unicode.org/faq/utf_bom.html#utf8-4 Reported by: Stefan Sperling Obtained from: OpenBSD MFC after: 5 days
-rw-r--r--lib/libc/locale/utf8.c8
1 files changed, 8 insertions, 0 deletions
diff --git a/lib/libc/locale/utf8.c b/lib/libc/locale/utf8.c
index 40f0e17..ef5784a 100644
--- a/lib/libc/locale/utf8.c
+++ b/lib/libc/locale/utf8.c
@@ -203,6 +203,14 @@ _UTF8_mbrtowc(wchar_t * __restrict pwc, const char * __restrict s, size_t n,
errno = EILSEQ;
return ((size_t)-1);
}
+ if ((wch >= 0xd800 && wch <= 0xdfff) ||
+ wch == 0xfffe || wch == 0xffff) {
+ /*
+ * Malformed input; invalid code points.
+ */
+ errno = EILSEQ;
+ return ((size_t)-1);
+ }
if (pwc != NULL)
*pwc = wch;
us->want = 0;
OpenPOWER on IntegriCloud